Class not included in the set of types for RPC

88 views
Skip to first unread message

Neil Aggarwal

unread,
Dec 18, 2024, 11:46:31 PM12/18/24
to google-we...@googlegroups.com
I am getting this error on the server:
Type 'com.propfinancing.puzzle.slitherlink.Line' was not included in the
set of types which can be
serialized by this SerializationPolicy or its Class object could not be
loaded. For security purposes,
this type will not be serialized.: instance = Line 0

And looking in the .gwt.rpc file, it is not listed there.

Interestingly, I see this:
com.propfinancing.puzzle.slitherlink.Line$STATUS
which is an Enum in that class so the GWT compiler obviously processed the
class.

I did not get any warnings or error messages from the GWT compiler as to
why it
decided it did not like the class so now I have to guess what it did not
like.

Is there a way to improve the messaging to the user to help understand
what happened?

Thank you,
Neil

--
Neil Aggarwal, (972) 834-1565, http://www.propfinancing.com
We offer 30 year loans on single family houses!

Craig Mitchell

unread,
Dec 19, 2024, 2:08:53 AM12/19/24
to GWT Users
At a guess, the inner enum needs to be told it can be serialised.  Ie:

import com.google.gwt.user.client.rpc.IsSerializable;

enum STATUS implements IsSerializable { ... }

Colin Alworth

unread,
Dec 19, 2024, 9:19:28 AM12/19/24
to GWT Users
Enums never need to be marked as serializable - unlike records, the Enum type itself is always serializable, and GWT-RPC assumes the same. From https://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes

A type is serializable and can be used in a service interface if one of the following is true:
...
 * The type is an enumeration. Enumeration constants are serialized as a name only; none of the field values are serialized.


That error message is indeed what is used when the standard serialization policy is read from disk, so you've resolved that earlier issue. Can you confirm that the policy file does include Line (that is, it is correctly reachable from the remote service instance)? If not, the GWT-RPC generator (run when the compiler is invoked) might not have seen a clear path to how this type could be used. Common reasons for that include declaring a field as being of type Object, which in your head means that any type could be assigned, but GWT-RPC doesn't want to mark every possibly class as potentially serializable (both for security reasons and to avoid generating serialization code for your client for every possible type).

Neil Aggarwal

unread,
Dec 19, 2024, 11:12:06 AM12/19/24
to google-we...@googlegroups.com

> Enumeration constants are serialized as a name only; none of the field values are serialized.

 

What are the consequences of not having the values?

Reading on the Internet, it means I can’t use valueOf() and ordinal().

But, does it work normally otherwise? 

Can I assign a constant value to a field, read that value, and compare the value to one of the
constants?

 

> Can you confirm that the policy file does include Line

 

It does not have Line in it:

 

@FinalFields, true

com._3dmathpuzzles.play.client.GetPuzzleService, false, false, false, false, _, 4203465842

com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle, true, true, false, false, com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle/2547295082, 2547295082

com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException, true, true, true, true, com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533, 3936916533

com.google.gwt.user.client.rpc.RpcTokenException, true, true, false, false, com.google.gwt.user.client.rpc.RpcTokenException/2345075298, 2345075298

com.google.gwt.user.client.rpc.XsrfToken, false, false, true, true, com.google.gwt.user.client.rpc.XsrfToken/4254043109, 4254043109

com.propfinancing.puzzle.Puzzle, true, false, false, false, com.propfinancing.puzzle.Puzzle/1723715424, 1723715424

com.propfinancing.puzzle.slitherlink.Box, true, true, false, false, com.propfinancing.puzzle.slitherlink.Box/1302152982, 1302152982

com.propfinancing.puzzle.slitherlink.Box$STATE, true, true, false, false, com.propfinancing.puzzle.slitherlink.Box$STATE/1639054469, 1639054469

com.propfinancing.puzzle.slitherlink.BoxWithDiagonals, true, true, false, false, com.propfinancing.puzzle.slitherlink.BoxWithDiagonals/2774485663, 2774485663

com.propfinancing.puzzle.slitherlink.Component, true, false, false, false, com.propfinancing.puzzle.slitherlink.Component/4011233562, 4011233562

com.propfinancing.puzzle.slitherlink.Line$STATUS, true, true, false, false, com.propfinancing.puzzle.slitherlink.Line$STATUS/1640439993, 1640439993

com.propfinancing.puzzle.slitherlink.NumberedBox, true, true, false, false, com.propfinancing.puzzle.slitherlink.NumberedBox/1782628205, 1782628205

com.propfinancing.puzzle.slitherlink.Puzzle, true, false, false, false, com.propfinancing.puzzle.slitherlink.Puzzle/2584703185, 2584703185

com.propfinancing.puzzle.slitherlink.RectangularPuzzle, true, false, false, false, com.propfinancing.puzzle.slitherlink.RectangularPuzzle/3177548746, 3177548746

com.propfinancing.puzzle.slitherlink.RectangularWithDiagonalsPuzzle, true, false, false, false, com.propfinancing.puzzle.slitherlink.RectangularWithDiagonalsPuzzle/3793384887, 3793384887

java.lang.Exception, true, false, true, false, java.lang.Exception/1920171873, 1920171873

java.lang.RuntimeException, true, false, true, false, java.lang.RuntimeException/515124647, 515124647

java.lang.String, true, true, true, true, java.lang.String/2004016611, 2004016611

java.lang.Throwable, true, false, true, false, java.lang.Throwable/2953622131, 2953622131

java.util.ArrayList, true, true, false, false, java.util.ArrayList/4159755760, 4159755760

java.util.HashMap, true, true, false, false, java.util.HashMap/1797211028, 1797211028

java.util.LinkedHashMap, true, true, false, false, java.util.LinkedHashMap/3008245022, 3008245022

 

> the GWT-RPC generator (run when the compiler is invoked) might not have seen a clear path to how this type could be used

 

Unfortunately, it is silent about the reason.

I am hoping we can improve it help the developer instead of leaving me to make guesses.

Jens

unread,
Dec 19, 2024, 4:41:11 PM12/19/24
to GWT Users
Neil Aggarwal schrieb am Donnerstag, 19. Dezember 2024 um 17:12:06 UTC+1:

> Enumeration constants are serialized as a name only; none of the field values are serialized.

What are the consequences of not having the values?

The consequence is that your enums should never ever have changing data stored. For example MyEnum.PERSON.getFriends().add(friend) is possible in Java but makes the enum constant mutable, which is bad. If enum constants are immutable then serializing the name or ordinal is enough to reconstruct the state.

> Can you confirm that the policy file does include Line

It does not have Line in it:

Does Line satisfy all rules? Default constructor, implements Serializable and only has Serializable fields? If yes, take a look at your GWT-RPC service method(s) declaration. Starting from the return type and the parameter types of the GWT-RPC method(s), will Line be discoverable directly or is it hidden behind some interface or super class or possibly class Object and GWT would need to find all the candidates that match these interfaces/super classes? If Line is hidden, do the interface / super class follow the rules? Maybe Line isn't the only class that is missing in the policy file?

As a workaround you can always add dummy methods to your GWT-RPC service, e.g. Line getDummyLine(), to make a class visible to GWT (or a Dummy class with a Line field and then use Dummy as return type).

-- J.


Colin Alworth

unread,
Dec 19, 2024, 4:46:55 PM12/19/24
to GWT Users
Improving the explanation of why Line isn't present would require exhaustively listing all the possible fields/etc that where is _isn't_ valid to assign a Line instance - Line isnt a subtype of String, Line isn't a subtype of List, the List in this field is List<Component> and Line isn't a subtype of Component, etc...

If you can point out in code how you expect to be able to send the Line type (which field in which other type that _is_ present in that list) it would be easier to offer an explanation.

Neil Aggarwal

unread,
Dec 19, 2024, 5:31:22 PM12/19/24
to google-we...@googlegroups.com

> Improving the explanation of why Line isn't present would require exhaustively listing all the possible

> fields/etc that where is _isn't_ valid to assign a Line instance

 

An exhaustive irrelevant list might be worse.

I was thinking it might be something within the class which the compiler did not like.

 

> If you can point out in code how you expect to be able to send the Line type (which field in which other

> type that _is_ present in that list) it would be easier to offer an explanation.

 

com.propfinancing.puzzle.slitherlink.Box is in the list.


It has this field:

  private ArrayList<Line> lines;

Neil Aggarwal

unread,
Dec 19, 2024, 5:43:59 PM12/19/24
to google-we...@googlegroups.com

> The consequence is that your enums should never ever have changing data stored

 

Got it.  I never modify the enum via code.  That would be a bit strange.

 

> Maybe Line isn't the only class that is missing in the policy file?

 

Yes, there are others which are missing.

 

> As a workaround you can always add dummy methods to your GWT-RPC service, e.g.

> Line getDummyLine(), to make a class visible to GWT

 

I added this method to com.propfinancing.puzzle.slitherlink.Box:

  public Line gwtGetLine() {

    return new Line();

  }

 

And the generated .gwt.rpc has Box, but still does not have Line:

 

@FinalFields, true

com._3dmathpuzzles.play.client.GetPuzzleService, false, false, false, false, _, 4203465842

com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle, true, true, false, false, com._3dmathpuzzles.slitherlink.RectangularWithDiagonalsPuzzle/2547295082, 2547295082

com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException, true, true, true, true, com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException/3936916533, 3936916533

com.google.gwt.user.client.rpc.RpcTokenException, true, true, false, false, com.google.gwt.user.client.rpc.RpcTokenException/2345075298, 2345075298

com.google.gwt.user.client.rpc.XsrfToken, false, false, true, true, com.google.gwt.user.client.rpc.XsrfToken/4254043109, 4254043109

com.propfinancing.puzzle.Puzzle, true, false, false, false, com.propfinancing.puzzle.Puzzle/1723715424, 1723715424

com.propfinancing.puzzle.slitherlink.Box, true, true, false, false, com.propfinancing.puzzle.slitherlink.Box/1302152982, 1302152982

com.propfinancing.puzzle.slitherlink.Box$STATE, true, true, false, false, com.propfinancing.puzzle.slitherlink.Box$STATE/1639054469, 1639054469

com.propfinancing.puzzle.slitherlink.BoxWithDiagonals, true, true, false, false, com.propfinancing.puzzle.slitherlink.BoxWithDiagonals/2774485663, 2774485663

com.propfinancing.puzzle.slitherlink.Component, true, false, false, false, com.propfinancing.puzzle.slitherlink.Component/4011233562, 4011233562

com.propfinancing.puzzle.slitherlink.NumberedBox, true, true, false, false, com.propfinancing.puzzle.slitherlink.NumberedBox/1782628205, 1782628205

com.propfinancing.puzzle.slitherlink.Puzzle, true, false, false, false, com.propfinancing.puzzle.slitherlink.Puzzle/2584703185, 2584703185

com.propfinancing.puzzle.slitherlink.RectangularPuzzle, true, false, false, false, com.propfinancing.puzzle.slitherlink.RectangularPuzzle/3177548746, 3177548746

com.propfinancing.puzzle.slitherlink.RectangularWithDiagonalsPuzzle, true, false, false, false, com.propfinancing.puzzle.slitherlink.RectangularWithDiagonalsPuzzle/3793384887, 3793384887

java.lang.Exception, true, false, true, false, java.lang.Exception/1920171873, 1920171873

java.lang.RuntimeException, true, false, true, false, java.lang.RuntimeException/515124647, 515124647

java.lang.String, true, true, true, true, java.lang.String/2004016611, 2004016611

java.lang.Throwable, true, false, true, false, java.lang.Throwable/2953622131, 2953622131

java.util.ArrayList, true, true, false, false, java.util.ArrayList/4159755760, 4159755760

java.util.HashMap, true, true, false, false, java.util.HashMap/1797211028, 1797211028

java.util.LinkedHashMap, true, true, false, false, java.util.LinkedHashMap/3008245022, 3008245022

 

 

Thank you,

 Neil

 

--

Neil Aggarwal, (972) 834-1565, http://www.propfinancing.com

We offer 30 year loans on single family houses!

 

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-web-toolkit/d7ee6beb-815d-44ab-8a3f-c292ee198e27n%40googlegroups.com.

Colin Alworth

unread,
Dec 19, 2024, 8:35:19 PM12/19/24
to GWT Users
Can you share the full contents of Line and Box? Or at least their class hierarchy and fields - methods are not important.

Only fields (and inheritance) are considered for RPC serialization - a method that returns a new instance won't cause that instance to be serialized (since it isn't part of the object's state).

Something has definitely changed since your last email - "Line$STATUS" was present before, but isn't now. Was that a deliberate change?

Craig Mitchell

unread,
Dec 19, 2024, 10:22:46 PM12/19/24
to GWT Users
> Enums never need to be marked as serializable

Apologies for my suggestion.  I'm not sure why I thought this.  I removed the IsSerializable from my enums that I transfer, and yep, they still work perfectly.

Neil Aggarwal

unread,
Dec 19, 2024, 11:45:29 PM12/19/24
to google-we...@googlegroups.com

> Can you share the full contents of Line and Box? Or at least their class hierarchy and fields - methods are not important.

 

I am attaching pared-down versions of Component, Box, and Line.

I am also attaching the generated .gwt.rpc

 

> Something has definitely changed since your last email - "Line$STATUS" was present before,

> but isn't now. Was that a deliberate change?

 

Yes. I have been paring down my classes to see if I can find out what the GWT Compiler

does not like so no luck so far.

Component.java
Box.java
Line.java
DB99B80F56EF7DDA5A31A4E322DCA283.gwt.rpc

Neil Aggarwal

unread,
Dec 20, 2024, 12:47:08 AM12/20/24
to google-we...@googlegroups.com

This is very interesting.  I added Line as a private member to Box:

  /** Testing a line instance */

  private Line line;

 

And an accessor:

  /** Test method for GWT */

  public Line getLine() {

    return line;

  }

 

Now, Box is not generated in the .gwt.rpc file (Box Box$STATE is still there).

 

If I mark those two items with @GwtIncompatible, Box appears again.

 

Thank you,

Neil

 

--

Neil Aggarwal, (972) 834-1565, http://www.propfinancing.com

We offer 30 year loans on single family houses!

 

From: Neil Aggarwal <ne...@propfinancing.com>
Sent: Thursday, December 19, 2024 10:45 PM
To: 'google-we...@googlegroups.com' <google-we...@googlegroups.com>
Subject: RE: Class not included in the set of types for RPC

 

> Can you share the full contents of Line and Box? Or at least their class hierarchy and fields - methods are not important.

 

I am attaching pared-down versions of Component, Box, and Line.

I am also attaching the generated .gwt.rpc

 

> Something has definitely changed since your last email - "Line$STATUS" was present before,

> but isn't now. Was that a deliberate change?

 

Yes. I have been paring down my classes to see if I can find out what the GWT Compiler

does not like so no luck so far.

 

Thank you,

Box.java
48B93B2E39A96BA47D497B72226E691A.gwt.rpc

Jens

unread,
Dec 20, 2024, 7:26:19 AM12/20/24
to GWT Users
What about the Point class? Line and Point are missing in the policy file so I guess Point might be the issue (or something that Point references)

-- J.

Colin Alworth

unread,
Dec 20, 2024, 7:33:40 AM12/20/24
to GWT Users
Are you sure you have no compiler errors, and -failOnError (or -strict) is set?

We can't see the code you won't share, so I can only make up scenarios for what might be wrong, as this is effectively "black box" testing from our part. Here's a scenario:

Your RemoteService type doesn't mention Box or Line directly, but Component
Component has other valid subtypes other than Box
Line doesn't actually compile at this time (or: some field that Line references doesn't compile, preventing it from compiling, etc).
But since there are other valid Component types that the compiler can see, GWT-RPC is satisfied that at least one Component subtype can be serialized.

If you remove Line from Box, suddenly Box can itself be compiled, so it can be serialized.

The same above can be true for "serialized" instead of "compiled" - if Line isn't actually able to be compiled and you didn't accurately share Line - for example, is Point serializable? I dont see it on the policy file examples either... do the other non-serializable types reference it or Line?

Neil Aggarwal

unread,
Dec 20, 2024, 10:23:04 AM12/20/24
to google-we...@googlegroups.com

> What about the Point class? Line and Point are missing in the policy file so I guess

> Point might be the issue (or something that Point references)

 

That was it!

 

Point referenced my own super-source version of Vector3f.

I forgot not mark Vector3f as Serializable.

 

Since it is super-source, it is not valid as-is so I excluded it from my
compile of my library.

 

The GWT compiler did not give me any errors or warnings so I did not

realize to look there.

 

I really think the RPC generator should not be silent here.

Puzzle references Point.  Puzzle was processed and present in the .gwt.rpc file

but Point was not processed.

Vector3f.java

Neil Aggarwal

unread,
Dec 20, 2024, 10:38:51 AM12/20/24
to google-we...@googlegroups.com

> Are you sure you have no compiler errors, and -failOnError (or -strict) is set?

 

No compiler errors.  I changed Vector3f back to non-serializable and ran the
build.  I am attaching the full output from Maven.

 

I have failOnError in my pom.xml:

                                             <plugin>

                                                            <groupId>net.ltgt.gwt.maven</groupId>

                                                            <artifactId>gwt-maven-plugin</artifactId>

                                                            <version>1.1.0</version>

                                                            <extensions>true</extensions>

                                                            <configuration>

                                                                           <failOnError>true</failOnError>

                                                                           <logLevel>INFO</logLevel>

                                                              <moduleName>com._3dmathpuzzles.play.DiagonalSlitherlink</moduleName>

                                                                           <systemProperties>

                                                                           <gwt.persistentunitcachedir>${project.build.directory}/gwt</gwt.persistentunitcachedir>

                                                                           </systemProperties>

                                                            </configuration>

                                             </plugin>                        

 

> We can't see the code you won't share

 

I am willing to share, but my library is HUGE.  It would not be useful to share it with you
until I pared it down to a test case.  Luckily, it looks like that is not going to be necessary.

 

> this is effectively "black box" testing from our part

 

Understood.  That is why I was trying to pare it down to a test case which would illustrate
what happened in a smaller subset of code.

MavenOutput.txt
Reply all
Reply to author
Forward
0 new messages