GWT 2.7.0: isAssignableFromRaw will fail when parameter to is java.lang.Object

114 views
Skip to first unread message

Frank Hossfeld

unread,
Jan 17, 2015, 8:34:36 AM1/17/15
to google-web-tool...@googlegroups.com

It look like that there is a bug inside the AssignabilityChecker class of GWT 2.7.0.

If you use the method isAssignableFromRaw(JClassType from, JClassType to) to check weather something is assignable to the „to“ parameter or not, the method will always fail if the value of the parameter „to“ is „java.lang.object“. 

The first thing this method does is to check if the „to“-parameter is the java.lang.object type. Therefor the method calls the method „isJavaLangObject(JClassType type)“. This method compares parameter type with  type.getOracle().getJavaLangObject(). But type.getOracle().getJavaLangObject() does not return a raw type. To solve this problem, the value of type.getOracle().getJavaLangObject() must be converted to a raw type.

The method is used to times. Once it is called from isAssignableFromGenericArrayType(JarrayType from, JClassType to), where the method isJavaLangObject(to) will work correct The second call is the one from isAssignableFromRaw, where the compare will fail.

To solve this problem, I have created a another method:

private static boolean isJavaLangObjectRawType(JClassType rawType) {

   return rawType == convertToRawIfGeneric(rawType.getOracle().getJvaLangObject());

}

and call this method from isAssignableFromRaw. Using this patch, everything works correct.

To test this error, you can download the mvp4g framework (trunk) from

https://code.google.com/p/mvp4g/source/checkout

and run the method:

testGeneratedClass

from the class:

com.mvp4g.rebind.config.loader.annotation.ServicesAnnotationsLoaderTest

I have created a patch and assigned it. Using the patch, the test will behave in the same way as it does with GWT 2.6.1.

Frank

 

Enviorement: OS X 10.10.1, Java 1.7, IntelliJ Ultimate Editition 14.0.2

 

 

AssignabilityChecker.java

Frank Hossfeld

unread,
Jan 19, 2015, 5:07:56 AM1/19/15
to google-web-tool...@googlegroups.com
Please can you prove that it is a bug or am I doing something wrong? I make an update to the AssignabilityChecker (this time with less code changes). If it is a bug, the changes should solve it.
AssignabilityChecker.java

Goktug Gokdogan

unread,
Jan 20, 2015, 3:53:03 PM1/20/15
to google-web-toolkit-contributors
I tried to reproduce the problem in GWT. I added following to JParameterizedTypeTest
    assertType("Object").isAssignableFrom("List");
    assertType("Object").isAssignableFrom("Integer");

and both cases doesn't fail.

I also don't understand what you mean about converting java.lang.Object to raw type. java.lang.Object is not a generic type so it cannot have a raw type.

Can you provide the exact types that your are passing or better reproduce the problem in JParameterizedTypeTest so we can take a look at the issue?


--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/3895a392-dd05-4450-813e-eceaf447adea%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Frank Hossfeld

unread,
Jan 20, 2015, 6:34:45 PM1/20/15
to google-web-tool...@googlegroups.com
I have tried to create a JUnit test for the AssignabilityChecker class, but that's not so easy. So I run the test from the JUnit test provided by the mvp4g project. You can easily reproduce the error. Just check out the mvp4g code from trunk, delete the AssignabilityChecker class and run the method testPath method from ServiceAnnotationsLoaderTest.

I am using the isAssignable method from AssignabilityChecker class. The value of the from parameter is something the SimpleService interface of mvp4g. The value of the to parameter is "java.lang.object". The "isAssignable" method calls "isAssignableFromRaw". 

The first thing this method does is to call "isJavaLangObject(to)". 

The code of the "isJavaLangObject" method looks like this:

private static boolean isJavaLangObject(JClassType type) {
return type == type.getOracle().getJavaLangObject();
}

type.getOracle().getJavaLangObject() returns "java.lang.Object<>". If this is compared to the raw type "java.lang.Object" the compare will fail. I have added two Screenshots. p02.png will show the value as the isAssignableFromRaw is called and p03.png will show the value which is returned by the method getJavaLangObject.

Will you be at the GWT.create in Munich?  If yes, I can show you the problem.
  
The screenshots can be downloaded here:


To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.

Goktug Gokdogan

unread,
Jan 20, 2015, 7:23:01 PM1/20/15
to google-web-toolkit-contributors
I'm not going to come Munich..

TypeOracle getJavaLangObject shouldn't return "java.lang.Object<>". From the screenshots, it looks like your are using a stub implementation for TypeOracle and that is probably doing the wrong thing.

To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/fa42088b-e9ab-48dd-b252-618fee582a1a%40googlegroups.com.

Goktug Gokdogan

unread,
Jan 20, 2015, 7:26:22 PM1/20/15
to google-web-toolkit-contributors

Frank Hossfeld

unread,
Jan 21, 2015, 1:47:21 AM1/21/15
to google-web-tool...@googlegroups.com
Arrrgh, you are right. It works well up to version 2.6.1. 

Frank Hossfeld

unread,
Jan 21, 2015, 3:32:10 AM1/21/15
to google-web-tool...@googlegroups.com
And thanks for you help, got it working!
Reply all
Reply to author
Forward
0 new messages