[WARN] In order to produce smaller client-side code, 'Object' is not allowed; consider using a more specific type

448 views
Skip to first unread message

David

unread,
Aug 18, 2011, 5:27:59 AM8/18/11
to google-we...@googlegroups.com
When I upgrade GWT version from 1.4.60 to 1.5.3 in my project, I run at hosted mode, I found many errors like below:
[WARN] In order to produce smaller client-side code, 'Object' is not allowed; consider using a more specific type

Although I can see the pages at hosted mode, but no data can't be retrieved from server, I think the error above results in it.
please note all works fine in web mode.

Anyone can help me? thanks in advance.

Paul Robinson

unread,
Aug 18, 2011, 9:26:07 AM8/18/11
to google-we...@googlegroups.com
GWT 1.5 introduced generics. Where before you might have had an RPC argument of "ArrayList bar", you will now have "ArrayList<Foo> bar"

See here:
http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/ReleaseNotes_1_5_Rpc
and here:
http://code.google.com/p/google-web-toolkit-doc-1-5/wiki/ReleaseNotes_1_5_ImportantNotes

If you just have "ArrayList bar", then it doesn't know anything about the class of things that will be in the list, and so GWT would have to search for every possible serializable class and generate javascript for handling the serialization of them. So the compiler makes you specify a supertype of the elements in the collection to narrow down the type of object in there. You should be as specific as possible.

HTH
Paul

> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/dRy1nVVulPgJ.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

Juan Pablo Gardella

unread,
Aug 18, 2011, 9:33:10 AM8/18/11
to google-we...@googlegroups.com
It's a WARN no an error. You can safely ignore it.

2011/8/18 David <luju...@gmail.com>

David

unread,
Aug 18, 2011, 10:33:48 PM8/18/11
to google-we...@googlegroups.com
thanks Juan Pablo Gardella, you said it is a WARN no an error, but why can'tno data be retrieved from server in hosted mode, and in web mode it work fine? I check my code, it should be ok, only there is the WARN message in hosted mode.

David

unread,
Aug 18, 2011, 10:39:15 PM8/18/11
to google-we...@googlegroups.com
Thanks Paul for you detail explaination. my model is as below:
public class CTableData implements IsSerializable {
    public String tableId;
    public int currentPage;
    public int lastPage;
    public long totalRows;

    public List <com.compositesw.web.client.ui.table.CRowData>rows = new ArrayList(); // List<CRowData>

    public Map <java.lang.String,java.util.List> filterStates = new HashMap(); // Map<String,Object> (filterName & filterState)

    public long totalErrorStatusRows;
    public long totalWarningStatusRows;
}

So we must specify the type of rows and filterStates? if it is, I must modify the codes in many place of my project, that worked fine in old version of GWT 1.4.60. do we have any other better solution for this?

Thanks,
David


Paul Robinson

unread,
Aug 19, 2011, 2:44:06 AM8/19/11
to google-we...@googlegroups.com
Converting an app to use generics is a pain, but once you've done it, it does make a lot of sense. It cuts down on a lot of casting and helps keep things type-safe. It's also a reminder about exactly what is supposed to be in each collection.

It's well worth taking the time to do the conversion to generics.

Paul

David

unread,
Aug 19, 2011, 3:07:53 AM8/19/11
to google-we...@googlegroups.com
but in my applicaiton:
public Map <java.lang.String,java.util.List> filterStates = new HashMap();

the value of filterStates is java.util.List, I can't specify the type for it, for in my app, this value is Object, it might be String, and other self-defined class/object, how to handle this?

Thanks,
David

Paul Robinson

unread,
Aug 19, 2011, 3:23:36 AM8/19/11
to google-we...@googlegroups.com
In that case, your compile will take longer and generate more javascript so your app will be slower to start for users than it need be. Methods for making this kind of thing work better include:
(1) Define an interface (or a base class) and have all classes you want in your list implement that interface. You can't do this directly with String because it's a final class. You can, however, create a wrapper class around String. Something like:

public interface State {}
public class StringState implements Serializable, State { String state; }

and then you have:
Map<String, List<State>> filterStates = new HashMap<String, List<State>>();

(2) Create a class that holds an instance of each type you might want to send, and give it an extra property that says what type of thing it contains:
public enum MyType {STRING, FOO, BAR }
public class State implements Serializable {
MyType type;
String string;
FOO foo;
BAR bar;
}

If you really don't know whether there's a String or some other object in your list, then it may be that you object model should be changed anyway. Otherwise you'll probably end up with lots of code like:
List list = ...;
for (Object o : list) {
if (o instanceof String) {
// do something with String
} else if (o instanceof Foo) {
// do something with Foo
}
}

HTH
Paul

David

unread,
Aug 19, 2011, 4:14:31 AM8/19/11
to google-we...@googlegroups.com
twu question:
1. what difference?
public interface State {}

and

 public class State implements Serializable {
         MyType type;
         String string;
         FOO foo;
         BAR bar;
     }

2. what difference between Serializable and IsSerializable?

Paul Robinson

unread,
Aug 19, 2011, 5:37:14 AM8/19/11
to google-we...@googlegroups.com

On 19/08/11 09:14, David wrote:
> twu question:
> 1. what difference?
> public interface State {}
>
> and
>
> public class State implements Serializable {
> MyType type;
> String string;
> FOO foo;
> BAR bar;
> }
It's just a matter of taste, of which one you prefer. Generally it's better to have a base class/interface that each rpc parameter will extend/implement if your object model will support it.
>
> 2. what difference between Serializable and IsSerializable? --

I think support for implementing Serializable was added in GWT 1.4. It means you don't have to have GWT classes (ie IsSerializable) in classes that are otherwise GWT-free and so helps support code sharing with non-GWT code/libraries.

See the GWT docs on serialization:
http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes

Paul

David

unread,
Aug 19, 2011, 10:58:30 AM8/19/11
to Google Web Toolkit
thanks for your quick answer, I will update the code as your guide.
but I am confusing whether this warning result in the exception that
any data can't be retrieved from server side in Gwt version 1.5.3, as
I mentioned, my app worked fin in gwt v1.4.60.

David
> See the GWT docs on serialization:http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunicat...
>
> Paul

Paul Robinson

unread,
Aug 19, 2011, 11:15:46 AM8/19/11
to google-we...@googlegroups.com

On 19/08/11 15:58, David wrote:
> thanks for your quick answer, I will update the code as your guide.
> but I am confusing whether this warning result in the exception that
> any data can't be retrieved from server side in Gwt version 1.5.3, as
> I mentioned, my app worked fin in gwt v1.4.60.

You haven't said what exception you get

David

unread,
Aug 19, 2011, 11:19:39 AM8/19/11
to Google Web Toolkit
the exception is that client can't get any data from server side, so
page can't show correctly at hosted mode in gwt v1.5.3.
please note web mode work fine.

Paul Robinson

unread,
Aug 19, 2011, 11:24:12 AM8/19/11
to google-we...@googlegroups.com
Copy & paste the exception and stack trace. It could well be nothing to do with the things we've been talking about.

David

unread,
Aug 19, 2011, 11:27:05 AM8/19/11
to Google Web Toolkit
I can't find any exception beside the warning message "In order to
produce smaller client-side code, 'Object' is not allowed; consider
using a more specific type Options " in hosted mode console.
> >> You haven't said what exception you get- Hide quoted text -
>
> - Show quoted text -

Paul Robinson

unread,
Aug 19, 2011, 11:35:25 AM8/19/11
to google-we...@googlegroups.com
I don't remember whether that should stop hosted mode from working. Either way, you know now how to get rid of the warning.


On 19/08/11 16:27, David wrote:
> I can't find any exception beside the warning message "In order to
> produce smaller client-side code, 'Object' is not allowed; consider
> using a more specific type Options " in hosted mode console.
>
> On Aug 19, 11:24 pm, Paul Robinson<ukcue...@gmail.com> wrote:

>> Copy& paste the exception and stack trace. It could well be nothing to do with the things we've been talking about.

David

unread,
Aug 19, 2011, 11:39:42 AM8/19/11
to Google Web Toolkit
ok, let me get ride of the warning firstly.
but I worried this is warn message not errro, that couldn't stop
hosted mode from working finally.
> >> - Show quoted text -- Hide quoted text -

ankit

unread,
Aug 20, 2011, 10:55:10 AM8/20/11
to Google Web Toolkit
hi everone..may be u forget to make any variable or class as
generic......i solved my problem by doing this.
Reply all
Reply to author
Forward
0 new messages