Repository navigation
Conversation
…rough non-exported modules. #178 got me to finally do this. As a test of this change, I built the Javadoc (including for non-exported modules) before and after it. The only differences in the generated files were in `serialized-form.html`. Some interesting cases arise with non-publicly accessible classes that act as supertypes of publicly visible classes. I handled them on a case-by-case basis: - I kept the annotations on `AbstractStringBuilder`. `AbstractStringBuilder` is the supertype of `StringBuilder` and `StringBuffer`. Its subclasses override _almost_ all its methods, but there are some that they do not override, and a few of those (at least `codePoints()` and the two `substring` methods) include non-primitive types in their signatures, which means that they're affected by the `@NullMarked` annotation on `AbstractStringBuilder`. It would technically "work" to remove all the _other_ annotations from that class, but that would be misleading and fragile. - I _did remove_ the annotation from `ChronoLocalDateImpl`. `ChronoLocalDateImpl` is the supertype of some public classes, but: - Its only annotation is on `equals`, which is overridden by those subclasses. - We haven't made it `@NullMarked`. Of course, another option - I haven't looked into it extremely deeply; maybe we should "should" annotate it. - I kept the annotations on `ConcurrentHashMap.CollectionView`: `CollectionView` is the supertype of `KeySetView`, and its `toArray` methods are available to users through that type. Plus, it's `@NullMarked` by virtue of being nested inside `ConcurrentHashMap`, so we "need" to annotate it correctly. - I now notice a few "missing" annotations in that area (`CollectionView.containsAll`, `KeySetView.equals`). I'll come back for them.
|
Yes, sorry, I should have said more. First: Despite all my overthinking about, I don't think I'm making things more fragile. (Let me know if you end up disagreeing!) The closest I'm coming to that is by removing the annotation from As for benefits: We have very rarely annotated non-publicly visible APIs in this repo. I look at this PR more as enacting that policy more widely than as changing anything. The improved consistency should help make clear to readers that we're not trying to annotate internals. But the thing usually gets me thinking about this is merge conflicts: Every annotation in our clone is a potential merge conflict when I pull in changes from OpenJDK upstream. Obviously that's a cost that I'm happy to pay for "real" nullness information. But it's sad when we get a merge conflict on an internal API that isn't adding any value. (On that front, I would also like to fix up some unnecessary formatting deviations that are left over from my sloppy removal of Checker-Framework-specific annotations years ago. I might get some of the easy cases later today.) |
msridhar
left a comment
There was a problem hiding this comment.
Didn't review every line carefully, but if there are issues we can fix in follow-ups
|
Thanks! And I should have actually replied to this:
The underlying principle is that we can omit class files that contain no JSpecify annotations. So, the fewer the classes that contain them, the better. The connection to #178 is that that PR observes that we could omit even classes that do contain JSpecify annotations if those classes aren't user-visible. However, because of cases like (I admit that it also didn't hurt that I noticed that, by putting together the Error Prone check that automated most of this PR, I was able to get further testing of the |
|
What is the point of removing annotations? I guess they could be removed at the "build" time. |
|
It would be a noble project to apply them consistently, especially if we had a strong reason to believe that the JDK could someday incorporate our nullness data. But the current setup of partial annotations for internals leads to merge conflicts without providing enough data to verify the annotations in the JDK. (Verifying the annotations would of course also require suppressions or code changes for cases in which the checker can't identify that something is safe, so it would be a larger project still, with correspondingly big costs and potential benefits.) |
This should address the error that just popped up, as [seen](https://github.com/jspecify/jdk/actions/runs/42861855071/job/129989794061?pr=179) in #179: ``` Reading package lists... Building dependency tree... Reading state information... Package g++-10 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Unable to locate package gcc-10 E: Package 'g++-10' has no installation candidate ``` It turns out that we haven't been using GCC 10 all this time, anyway, so it's safe to remove, Gemini explains: > Yes, this is directly caused by GitHub's `ubuntu-latest` migration from Ubuntu 24.04 to Ubuntu 26.04 ([actions/runner-images#14748](actions/runner-images#14748), rolling out October 19 – November 19, 2026): > > 1. **Why it failed:** [jspecify.yml](https://github.com/jspecify/jdk/blob/main/.github/workflows/jspecify.yml#L11-L30) uses `runs-on: ubuntu-latest` and runs `sudo apt-get install gcc-10 g++-10 ...`. Ubuntu 26.04 dropped `gcc-10` and `g++-10` from its APT repositories. > 2. **Why we don't even need `gcc-10` / `g++-10`:** When [jspecify.yml](https://github.com/jspecify/jdk/blob/main/.github/workflows/jspecify.yml) was originally created (#114), the `apt-get install gcc-10 g++-10` line was copied from upstream OpenJDK's [build-linux.yml](https://github.com/jspecify/jdk/blob/main/.github/workflows/build-linux.yml#L128-L141)—**without** the accompanying `update-alternatives` command (or `CC`/`CXX` configure arguments). As a result, `./configure` in `jspecify.yml` has never actually used `gcc-10`/`g++-10`; it has always just used the runner's pre-installed default `/usr/bin/gcc` and `/usr/bin/g++` (GCC 13 on Ubuntu 24.04, and GCC 15 on Ubuntu 26.04). > 3. **Recommended fix:** Simply drop `gcc-10 g++-10` from the `apt-get install` line in [jspecify.yml](https://github.com/jspecify/jdk/blob/main/.github/workflows/jspecify.yml#L29). Current OpenJDK 28 sources in this branch already support GCC 15 (which is also what your local workstation has configured in `build/linux-x86_64-server-release`), and `jspecify.yml` already passes `--disable-warnings-as-errors`. (If anything else in Ubuntu 26.04 ever causes trouble, you could also pin `runs-on: ubuntu-24.04` to match upstream [main.yml](https://github.com/jspecify/jdk/blob/main/.github/workflows/main.yml#L60).) (Maybe we *should* find the version that upstream uses, install that, and run `update-alternatives` for that. But for now, I'm happy to get the build working again, and we can cross that bridge when we come to it.)
Some of these don't even matter to its existing users. For example, we're never considering adding a nullness annotation to a module based on whether it "looks like public API." But it's good to future-proof, especially since the two overloads have behavior inconsistent with each other before this CL. Other cases probably _could_ matter even now. Maybe I should rerun some of our annotation-adding tools over the JSpecify JDK clone again.... (This came up during jspecify/jdk#179.) Some specifics: - A record parameter is always visible (if the enclosing record type is), but it shows up as in the AST as the backing `FIELD`, which is `private`. - Starting directly on a method or field (rather than on, say, a type somewhere inside it) was wrongly returning "not a public API" instead of looking at the visibility of that symbol. PiperOrigin-RevId: 1021439393
(noticed during #179) Interesting cases: - I notice that `removeAll` can handle null elements if it falls into the `c instanceof Set<?> && c.size() > t.length` case or the `map.table` null case. I'm not sure whether to consider that enough for the parameter's type argument to be nullable or not. Is it fundamentally different from noticing how the method can handle an argument with a nullable element type _if that argument happens to contain no elements_? (By _that_ logic, even `ImmutableList.copyOf` should use a nullable type argument for its parameter!) I ended up moving to including a non-null bound on the wildcard. - `contains` and `remove` are defined in the superclass `CollectionView`, and each can handle `null` in at least one package-private subclasses, despite the blanket `@throws` clause in the documentation. But they do throw for `KeySetView`, which is the only user-visible type. So I went with a non-null type there, as well. - Instead of declaring the type parameter of `KeySetView` as `V extends @nullable Object`, we could leave it as `V` but declare the obscure `getMappedValue()` as returning `@Nullable V`. (I see no calls to that method in our depot, and I don't think I knew it existed before today.) I decided to go with the principled `V extends @nullable Object` approach, which might require a handful of updates in Google's Kotlin code (to declare `ConcurrentHashMap.KeySetView<K, V?>` instead of `ConcurrentHashMap.KeySetView<K, V>`, but they should probably use `Set<K>` instead, anyway).
The primary goal here is to make future merges easier. (I have had trouble in past merges that I traced to spurious diffs.) Most of the changes are about removing whitespace that I had regrettably left behind when removing Checker-Framework-specific annotations from typetools/checker-framework. There are other changes, too, including restoring the `ThreadGroup.destroy()` method that I'd removed in a prior bad merge. (This doesn't matter for nullness purposes, but it, too, could reduce the chances of problems in future merges.) Gemini (which did the work) elaborates: > ### Summary of Changes > > 1. **Top-level files (3 files)** > - Removed Checker Framework leftovers `azure-pipelines.yml` and `README-rewritten-jdk-history` (`git rm`). > - Reverted [.gitignore](https://github.com/jspecify/jdk/blob/main/.gitignore) to match `openjdk/master`. > > 2. **Merge-conflict restoration & CF leftovers** > - [ThreadGroup.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/lang/ThreadGroup.java): Restored the broken/commented-out `destroy()` Javadoc, `@Deprecated(since="16", forRemoval=true)`, and `public final void destroy() {}` from `openjdk/master`, and removed its 3 `@SuppressWarnings("index:array.access.unsafe.high")` annotations. > - Removed all remaining 38 leftover `@SuppressWarnings(...)` annotations across 14 files, reverted the modified `@SuppressWarnings` in [EnumMap.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/EnumMap.java) back to `@SuppressWarnings("unchecked")`, reverted the temporary `result` variable in [ResourceBundle.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/ResourceBundle.java) back to `return sb.toString();`, and removed the 2 CF comments in [HashMap.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/HashMap.java) and [ListIterator.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/ListIterator.java). > - Removed all 18 leftover `@Override` annotations ([AbstractCollection.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/AbstractCollection.java), [PrimitiveIterator.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/PrimitiveIterator.java), and [Thread.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/lang/Thread.java)). > - Reverted all 7 explicit diamond type arguments in [TemporalQueries.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/time/temporal/TemporalQueries.java) back to `new TemporalQuery<>()`. > > 3. **Unused & duplicate imports** > - Removed 98 unused `org.jspecify.annotations` imports (95 `Nullable`, 3 `NonNull`) while keeping the placement/surrounding blank lines of retained JSpecify imports unchanged. > - Removed the duplicate `import org.jspecify.annotations.Nullable;` (and its extra blank line) at the top of [AbstractChronology.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/time/chrono/AbstractChronology.java#L62-L64) (keeping the grouped JSpecify imports further down the import block). > - Removed the 4 unused non-JSpecify imports in [InheritableThreadLocal.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/lang/InheritableThreadLocal.java), [Reference.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/lang/ref/Reference.java), and [UUID.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/UUID.java), and removed the duplicate `import java.lang.ref.WeakReference;` in [WeakHashMap.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/WeakHashMap.java) (restoring upstream import order). > > 4. **SQL postfix array annotations & `CompletableFuture` wraps & whitespace normalization** > - Standardized [CallableStatement.java](https://github.com/jspecify/jdk/blob/main/src/java.sql/share/classes/java/sql/CallableStatement.java#L974) (`setBytes`) and [ResultSet.java](https://github.com/jspecify/jdk/blob/main/src/java.sql/share/classes/java/sql/ResultSet.java#L2099) (`updateBytes`) to `byte x @nullable []`. > - Undid all 9 line-wrap/unwrap diffs in both directions in [CompletableFuture.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/concurrent/CompletableFuture.java). > - Normalized 2,776 unchanged-token whitespace gaps, 147 gaps around `@Nullable`/`@NonNull` (including tabs in Swing/AWT parameter lists and trailing-space newlines in [Attributes.java](https://github.com/jspecify/jdk/blob/main/src/java.naming/share/classes/javax/naming/directory/Attributes.java#L102) and [NamespaceContext.java](https://github.com/jspecify/jdk/blob/main/src/java.xml/share/classes/javax/xml/namespace/NamespaceContext.java#L207)), 69 gaps around `@NullMarked`, and `extends Object` in [ConcurrentHashMap.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java). > > ### Verification > > - **Exact token & whitespace verification vs `openjdk/master`** across all 879 modified `.java` files: > - `0` unchanged-token whitespace diffs > - `0` inserted-region whitespace anomalies (outside kept JSpecify import placement) > - `0` unused JSpecify imports > - `0` non-JSpecify annotations added or removed (exact preserved counts: `4038` `@Nullable`, `578` `@NullMarked`, `43` `@NonNull`, `8` `@NullUnmarked`) > - Only remaining non-annotation / non-import / non-`extends Object` hunks are the 25 intentional ones: [module-info.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/module-info.java#L138), [Provider.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/security/Provider.java#L573) (3 `?>`), [Objects.java](https://github.com/jspecify/jdk/blob/main/src/java.base/share/classes/java/util/Objects.java#L70) (J2CL overload), and the 20 intentional JSpecify comments. > - **Build**: `make jdk` completed with exit code `0` (`Finished building target 'jdk' in configuration 'linux-x86_64-server-release'`). I tested the results with the same Javadoc-based methodology as in #179. I saw some changes in "auxiliary" files like the `class-use` files, but the only change to "actual Javadoc" I saw was in `ThreadGroup`, where `destroy()` returns, as expected.
#178 got me to finally do this.
As a test of this change, I built the Javadoc (including for non-exported modules) before and after it. The only differences in the generated files were in
serialized-form.html.Some interesting cases arise with non-publicly accessible classes that act as supertypes of publicly visible classes. I handled them on a case-by-case basis:
I kept the annotations on
AbstractStringBuilder.AbstractStringBuilderis the supertype ofStringBuilderandStringBuffer. Its subclasses override almost all its methods, but there are some that they do not override, and a few of those (at leastcodePoints()and the twosubstringmethods) include non-primitive types in their signatures, which means that they're affected by the@NullMarkedannotation onAbstractStringBuilder. It would technically "work" to remove all the other annotations from that class, but that would be misleading and fragile.I did remove the annotation from
ChronoLocalDateImpl.ChronoLocalDateImplis the supertype of some public classes, but:equals, which is overridden by those subclasses.@NullMarked. Of course, another optionI kept the annotations on
ConcurrentHashMap.CollectionView:CollectionViewis the supertype ofKeySetView, and itstoArraymethods are available to users through that type. Plus, it's@NullMarkedby virtue of being nested insideConcurrentHashMap, so we "need" to annotate it correctly.CollectionView.containsAll,KeySetView.equals). I'll come back for them.