jsinterop-base icon indicating copy to clipboard operation
jsinterop-base copied to clipboard

Nullness annotations not included in gwt.xml

Open zbynek opened this issue 1 year ago • 6 comments

https://github.com/google/jsinterop-base/commit/40918a2fa860ac62849dec3bf73d752df7be48c0 adds the JSpecify annotations, but doesn't add them to gwt.xml, leading to

[ERROR] Errors in 'jar:file:/.../base-1.0.2.jar!/jsinterop/base/Js.java'
         [ERROR] Line 140: Nullable cannot be resolved to a type

For my own use-case it would be great if JSInterop would just add those classes to source path. If you prefer to leave that to the users, it would be nice do document this.

zbynek avatar Oct 23 '24 07:10 zbynek

For anyone who ran into this, adding a new file org/jspecify/Annotations.gwt.xml with the following content

<?xml version="1.0" encoding="UTF-8"?>
<module>
    <source path='annotations' />
</module>

and the corresponding <inherits name="org.jspecify.Annotations"/> to your own *.gwt.xml module definition should be good enough until this is included in JsInterop.

zbynek avatar Oct 23 '24 10:10 zbynek

Maybe also worth pointing out that JsInterop 1.0.2 won't work with the current release of GWT because of https://github.com/gwtproject/gwt/issues/10001 -- fix is included in upcoming 2.12 release.

zbynek avatar Oct 23 '24 11:10 zbynek

Our GWT knowledge got quite bit dusty nowadays. I forgot if it was safe to supply org/jspecify/Annotations.gwt.xml from here. What happens if somebody has the same file? Probably removing it in the future also becomes a breaking change.

Was there are different workaround here since this is annotation only dependency used as byte-code? @niloc132

gkdn avatar Oct 24 '24 00:10 gkdn

I can't confirm that annotation sources are required to compile by GWT 2, only bytecode seems needed - that matches my understanding in the past of how the compiler functions here.

However I believe I have seen errors where the unit cache gets into a bad state after seeing an error like this - generally when you see this make sure yo have a clean build - gwt unit cache gets in a bad state?

I am seeing this error in the GWT 2.12 RC though (due to ship as soon as the release notes file is complete) - the root of this specific error is that com.google.jsinterop:base:1.0.2 is missing its required dependency on org.jspecify:jspecify (I assume version 1.0.0). This is a bug for jsinterop-base itself to fix, though you can workaround it by manually adding the dependency. This will not work for j2cl in maven - similarly to running j2cl in bazel, j2cl-maven-plugin requires that each library correctly lists its own dependencies, and you can see that https://github.com/google/jsinterop-base/blob/92d499b1b82fc870d2af6a550857831a0e9066a5/java/jsinterop/base/BUILD#L15-L24 does not match https://search.maven.org/artifact/com.google.jsinterop/base/1.0.2/jar

With that in place, I get a new error - it looks as though GWT's BinaryTypeReferenceRestrictionsChecker's BinaryTypeReferenceVisitor doesn't consider this to be an annotation, but some other binary type ref, so it requires that the type compiles.

Compiling module com.example.Project
   Tracing compile failure path for type 'jsinterop.base.JsPropertyMap'
      [ERROR] Errors in 'jar:file:/home/colin/.gradle/caches/modules-2/files-2.1/com.google.jsinterop/base/1.0.2/e158588ccbe496850741392ac505ee87fd6276f0/base-1.0.2.jar!/jsinterop/base/JsPropertyMap.java'
         [ERROR] Line 31: No source code is available for type org.jspecify.annotations.Nullable; did you forget to inherit a required module?
   Tracing compile failure path for type 'jsinterop.base.JsArrayLike'
      [ERROR] Errors in 'jar:file:/home/colin/.gradle/caches/modules-2/files-2.1/com.google.jsinterop/base/1.0.2/e158588ccbe496850741392ac505ee87fd6276f0/base-1.0.2.jar!/jsinterop/base/JsArrayLike.java'
         [ERROR] Line 33: No source code is available for type org.jspecify.annotations.Nullable; did you forget to inherit a required module?
   [ERROR] Aborting compile due to errors in some input files

Maybe something to do with this being a type-use case? I tried making a few quick samples that demonstrate the issue directly, but so far no good - @zbynek can you file this for GWT, so we can hunt it down further? We can probably do a quick follow-up release for this, and I can fill in the rest of the details when we figure it out.

niloc132 avatar Oct 28 '24 16:10 niloc132

Hi, the need for source for type-use annotations is something that we've grappled with on the Guava side since ~2018 (bug 78349518, for any curious Googlers). It seems that even some "type-use-only" locations can work (or at least used to), such as when we used <T extends @NonNull Object> for some of our type-parameter declarations. But many (most?) locations for type-use annotations have not worked for us.

From the JSpecify side, I can say that this is something that we've hoped to help with by adding a .gwt.xml there for a few years, and we've been waiting largely because we weren't sure whether to put it in the main JSpecify jar or in a separate jar. We'd been working around it in Guava, but now you are the second project in the past couple months (after Dagger) where we've seen trouble reported, so maybe we should make it happen.

cpovirk avatar Oct 28 '24 21:10 cpovirk

@cpovirk are there any details you can add to https://github.com/gwtproject/gwt/issues/10020? I think I have the fix for this (based on a medium/small project that uses gradle+gwt), but I don't yet have a way to unit test the compiler change, the "obvious" example of compiling <T extends @Foo Object> with some Foo.class on the classpath but without source available to GWT hasn't tripped the bug.

niloc132 avatar Oct 29 '24 00:10 niloc132

To reiterate, jsinterop-base is still broken in maven central - the 1.0.2 release uses jspecify, but is missing that dependency from the pom.

niloc132 avatar Nov 07 '24 19:11 niloc132

@niloc132 do you mind sending a PR for the pom? @mollyibot we should do a new release for jsinterop-base at one point (but only for jsinterop-base) with the updated pom.

gkdn avatar Nov 08 '24 01:11 gkdn

Sure, we canl do a new release after the pr.

mollyibot avatar Nov 08 '24 02:11 mollyibot

Looks like this is done in https://github.com/google/jsinterop-base/pull/20, should we do a release now?

mollyibot avatar Nov 14 '24 01:11 mollyibot

Can you help test @zbynek @niloc132 this snapshot https://oss.sonatype.org/content/repositories/comgooglejsinterop-1038

mollyibot avatar Nov 15 '24 23:11 mollyibot

I can confirm that this staging 1.0.3 release works with GWT 2.12.1, jsinterop-annotations 2.0.2, and elemental2-* 1.2.3. Tested both a Maven and a Gradle project.

niloc132 avatar Nov 16 '24 12:11 niloc132

Thanks for testing it!

mollyibot avatar Nov 16 '24 18:11 mollyibot

The staging 1.0.3 works for me as well, thanks!

zbynek avatar Nov 17 '24 22:11 zbynek

Thanks for confirming it. I will close the snapshot.

mollyibot avatar Nov 18 '24 06:11 mollyibot