Skip to content

Create a projection anchor in Nullable, and use ## links. - #816

Merged
cpovirk merged 2 commits into
mainfrom
doublehash
Jul 15, 2026
Merged

cpovirk merged 2 commits into
mainfrom
doublehash

Conversation

@cpovirk

@cpovirk cpovirk commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Currently, NonNull links to Nullable.html#projection, but there is no such anchor by that name. I've added one at the definition. This is still not as clear as having a section would be, but I'm not sure whether we want a section. Another option would be to change the text in NonNull to refer to "nullable projection" as...

"when `Nullable` is [applied to](Nullable#meaning-per-each-kind-of-type-usage-heading) a type variable

...or something to that effect.

(For the anchor, I introduced a span. If I make it completely empty, then I get a warning from Javadoc. Thus, I decided to make it cover the "title" of the list item.)

As for using ## links: That's what I had come here to do before I found the problem with #projection. Compare google/guava#8346. From what I've seen, their main advantage is when linking to other projects (since you can link to, say, Character##supplementary instead of https://docs.oracle.com/en/java/javase/26/docs/api/java.base/java/lang/Character.html#supplementary. But I figure we might as well use them for links inside JSpecify, too.

Currently, `NonNull` links to `Nullable.html#projection`, but there is no such anchor by that name. I've added one at the definition. This is still not as clear as having a section would be, but I'm not sure whether we want a section. Another option would be to change the text in `NonNull` to refer to "nullable projection" as...

```
"when `Nullable` is [applied to](Nullable#meaning-per-each-kind-of-type-usage-heading) a type variable
```

...or something to that effect.

(For the anchor, I introduced a `span`. If I make it completely empty, then I get a warning from Javadoc. Thus, I decided to make it cover the "title" of the list item.)

As for using [`##` links](https://docs.oracle.com/en/java/javase/26/docs/specs/javadoc/doc-comment-spec.html#:~:text=references%20to%20arbitrary%20URI%20fragments): That's what I had come here to do before I found the problem with `#projection`. Compare google/guava#8346. From what I've seen, their main advantage is when linking to other projects (since you can link to, say, `Character##supplementary` instead of `https://docs.oracle.com/en/java/javase/26/docs/api/java.base/java/lang/Character.html#supplementary`. But I figure we might as well use them for links inside JSpecify, too.
@cpovirk

cpovirk commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator Author

Huh: From my experience in #812, I thought I'd confirmed that Javadoc runs already didn't work with versions like Java 21 11. Yet I'm seeing a failure under at least Java 17:

Error: /home/runner/work/jspecify/jspecify/src/main/java/org/jspecify/annotations/Nullable.java:85: error: unexpected text

 *       this way is called "nullable projection" ({@linkplain NonNull##projection non-null
                                                   ^
Error: /home/runner/work/jspecify/jspecify/src/main/java/org/jspecify/annotations/NullMarked.java:67: error: unexpected text
 *       and {@code @NonNull} are {@linkplain Nullable##applicability <b>not applicable</b>}, such
                                  ^
Error: /home/runner/work/jspecify/jspecify/src/main/java/org/jspecify/annotations/NonNull.java:41: error: anchor already defined: "projection"
 * <h2 id="projection">Non-null projection</h2>
       ^
Error: /home/runner/work/jspecify/jspecify/src/main/java/org/jspecify/annotations/NonNull.java:82: error: unexpected text
 * <p>{@linkplain Nullable##projection Nullable projection} serves the equivalent purpose in the
      ^
Error: /home/runner/work/jspecify/jspecify/src/main/java/org/jspecify/annotations/NonNull.java:90: error: unexpected text
 * <p>{@code @NonNull} is applicable in all the {@linkplain Nullable##applicability same locations}
                                                ^
Error: /home/runner/work/jspecify/jspecify/src/main/java/org/jspecify/annotations/NullUnmarked.java:55: error: unexpected text
 * <p>The effects of being null-marked are described in the {@linkplain NullMarked##effects Effects}
                                                            ^
Error: /home/runner/work/jspecify/jspecify/src/main/java/org/jspecify/annotations/NullUnmarked.java:75: error: unexpected text
 * The information in the {@linkplain NullMarked##where Where it can be used} section of {@code
                          ^
7 errors
> Task :javadoc FAILED

Maybe 17 is new enough to be stricter about errors but not new enough to recognize the new syntax? But I'd still have to figure out why 11 works at all....

Ah, now I remember:

jspecify/build.gradle

Lines 40 to 42 in 8bb43e2

if (javaVersion.canCompileOrRun(15)) {
withJavadocJar()
}

Yet more motivation for #813?

This adds support for `##` links.

It's very possible that I should just bump this all the way to 26: We want to use the newest version of Javadoc to build our release Javadoc, just as we already do for snapshot Javadoc. So, if we were to skip building Javadoc under earlier versions, that could act as a free check during [the release process](#305) that we're using the right version. Then we'd want to bump this version [when we bump our Java version elsewhere](#815). The downside would be that local users who build with Java 21 can no longer build Javadoc (though I'm not sure it's that hard to just [have Gradle download a newer version for them](https://github.com/jspecify/jspecify/issues/813)—and how many people really care whether they can build our Javadoc locally, especially as long as it doesn't fail in a way that breaks the whole build?). But that might become the case anyway if we [start to use Markdown Javadoc](#817), which would raise the minimum [to Java 23](https://openjdk.org/jeps/467), and maybe we'd unknowingly use a feature that requires something even newer.

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Changes look consistent to me, but I do not understand the intricacies of different Javadoc versions.

@wmdietl wmdietl assigned cpovirk and unassigned wmdietl Jul 15, 2026
@cpovirk

cpovirk commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. Since you approved #818 (which I've merged), we shouldn't have to worry about different Java versions, so I think we're good.

And thank you for raising that: In #818, I should really have removed the bit that I'm updating here:

jspecify/build.gradle

Lines 40 to 42 in 0f5f17f

if (javaVersion.canCompileOrRun(15)) {
withJavadocJar()
}

I'll do that separately.

@cpovirk

cpovirk commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator Author

@kevinb9n, this is going to create merge conflicts with your changes :\

@cpovirk
cpovirk merged commit ea1b5bc into main Jul 15, 2026
14 checks passed
@cpovirk
cpovirk deleted the doublehash branch July 15, 2026 15:07
@kevinb9n

Copy link
Copy Markdown
Collaborator

No problem and I replicated this approach to my new links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants