isInstanceOf/isNotInstanceOf can't find supertypes under GWT (if class metadata is off?)
- Dominant language
- Java
- Stars
- 2.8k
- Forks
- 275
- Avg merge
- 7m
- Merged PRs (30d)
- 4
Description
If I adopt `isInstanceOf` in Guava, various tests fail. These are tests that worked fine with `assertTrue(foo instanceof Bar)`. Truth has special support for `isInstanceOf` under GWT, but it can't always work: My understanding is that `getSuperclass()` is unavailable if `-XdisableClassMetadata` is set:
https://code.google.com/p/google-web-toolkit/wiki/NoClassMetadataOptimization
https://code.google.com/p/google-web-toolkit/source/detail?r=4790
There are various directions we could go here. We can fail `isInstanceOf` and/or `isNotInstanceOf` calls under GWT, whether unconditionally or only if class metadata is absent. We could fail some in one set of circumstances and some in the other. If we try to do our best without class metadata, we could add some warnings to the failure message. Or we can remove the methods entirely from GWT. (But that seems heavy handed, since I expect few users to run tests with class metadata off. Speaking of which, why not just turn on class metadata in Guava's tests? Our goal is to make sure that our prod code functions correctly with it off. This has the unfortunate effect of forcing our test code to do the same.)
I suggest something like this:
- `isNotInstanceOf` fails under `-XdisableClassMetadata`, since we it can't do its job unless it's checking that the class is exactly `==` to another
- `isInstanceOf` either does the same thing, or it tries to check `==` and then fails with a warning that it might be failing wrongly
(Also, we should expand our tests that these methods work correctly with class metadata on. We have some tests already, but I don't think we currently exercise `isInstanceOf(SomeInterface.class)`.)
Contributor guide
Assessment
This issue has not been assessed yet.