Skip to content

Commit

Permalink
Strip @Nullable annotations from GWT sources.
Browse files Browse the repository at this point in the history
If we use `@Nullable`, the GWT compiler requires access to _the source code for `@Nullable`_ -- at least when `@Nullable` appears in _certain_ locations (type parameter bounds, type arguments, maybe others?). When we began using those annotations in those locations, I inserted a workaround into our own build to supply access to the source code for `@Nullable`. (That required not only depending on that source code but also providing a hacky, local `.gwt.xml` file. That means that our _users_ would _also_ need to do both of those things, which we really shouldn't require.) I had intended to improve upon this before the 31.0 release, but I didn't make a note about it in the right place :(

The fix of simply removing the annotations works fine, since only the GWT compiler ever sees these sources, and it doesn't care about type annotations.

(OK, our j2cl users could eventually care about the lack of annotations. But we haven't yet we applied `@NullMarked` to our classes externally, so the difference to them is between "lack of nullness information" and "possibly null" -- which means essentially nothing.)

(One way to look at this CL is as an edited, very partial rollback of CL 364918297.)

RELNOTES=Fixed [GWT compilation failure](https://groups.google.com/g/guava-discuss/c/I32pgyyj1N8/m/pXcyky2hAgAJ) introduced in release 31.0.
PiperOrigin-RevId: 399190627
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Sep 27, 2021
1 parent 7396bab commit 0ad6d6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
21 changes: 6 additions & 15 deletions guava-gwt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<classifier>sources</classifier>
</dependency>
</dependencies>
<build>
<plugins>
Expand All @@ -134,8 +129,6 @@
<!-- 2. Don't include the source in the jar (since that would let users depend on it from GWT client code, which is compiled from source). -->
<exclude>**/ForceGuavaCompilation*</exclude>
<exclude>**/DummyJavadocClass*</exclude>
<!-- (unrelated interruption: Also don't include our fabricated CF GWT module descriptor. -->
<exclude>**/Qual.gwt.xml</exclude>
</excludes>
</configuration>
</plugin>
Expand All @@ -146,8 +139,6 @@
<!-- 3. Don't include it in the source jar (since it's really more of a "test" than it is production code). -->
<exclude>**/ForceGuavaCompilation*</exclude>
<exclude>**/DummyJavadocClass*</exclude>
<!-- (unrelated interruption: Also don't include our fabricated CF GWT module descriptor. I don't think anyone should be using our *sources* jar, anyway, at least not as an input to GWT compilation, but it seems safest to exclude here, just as we do for maven-jar-plugin, to be safe. -->
<exclude>**/Qual.gwt.xml</exclude>
</excludes>
</configuration>
</plugin>
Expand Down Expand Up @@ -308,17 +299,17 @@
<include name="**/InternalFutureFailureAccess.java" />
</fileset>
</copy>
<!-- We fabricate a GWT module to cover the CF annotations. Then we inherit it in ForceGuavaCompilation.gwt.xml. -->
<echo file="${project.build.directory}/guava-gwt-sources/org/checkerframework/checker/nullness/qual/Qual.gwt.xml">
&lt;module&gt;&lt;source path="" /&gt;&lt;/module&gt;
</echo>
<!-- TODO(cpovirk): DO NOT RELEASE in this state: I suspect that downstream users of guava-gwt will see their compilation fail from the "missing" CF annotations (whether because those sources are missing entirely or because they're present but without a module descriptor). -->
<!-- In contrast to what we do with our *own* sources (i.e., those from guava, guava-testlib, and guava-tests), we *don't* copy the CF annotations to guava-gwt-sources (and so we don't need to unpack them ourselves at all). If we did, they would end up in our generated jar. And we don't need to, anyway: The GWT plugin picks them up automatically because of the <classifier>source</classifier> dependency above. -->
<copy toDir="${project.build.directory}/guava-test-gwt-sources">
<fileset dir="${project.build.directory}/guava-test-sources">
<contains text="@GwtCompatible"/>
</fileset>
</copy>
<replace token="@Nullable" value="">
<fileset dir="${project.build.directory}">
<include name="guava-gwt-sources/**/*.java"/>
<include name="guava-test-gwt-sources/**/*.java"/>
</fileset>
</replace>
</target>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<inherits name="com.google.common.xml.Xml" />
<inherits name="com.google.thirdparty.publicsuffix.PublicSuffixPatterns" />
<inherits name="com.google.thirdparty.publicsuffix.PublicSuffixType" />
<inherits name="org.checkerframework.checker.nullness.qual.Qual" />

<!-- com.google.common.testing.Testing is located in
GuavaTests under guava-gwt/test -->
Expand Down

2 comments on commit 0ad6d6d

@olegdizhak1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔🤔🤔

@olegdizhak1
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Учусь

Please sign in to comment.