-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scope of package-level default annotations #8
Comments
Comments from the document:
|
Additionally, it's not clear how the scope is applied across module dependencies. E.g. if module A depends on B, both have the same package, which is annotated with a default annotation, should A get it as well? What if B is a library jar, not a source module? |
Naively I would suggest that no defaulting mechanism should ever affect code in different modules under any circumstances. |
To the original question, what are the advantages of either approach? (direct package only vs. subpackages in same module) |
Because there is technically no hierarchy of Java packages (all packages are independent from each other) my intention was for @DefaultNotNull on package a.b.c to not affect "sub-"packages a.b.c.{d,e,f.g} etc. I tried to make that clearer in the proposal writeup. Please reopen if you disagree. |
I think there should be an option to make subpackages inherit the |
The current approach has the advantage that there's no chance of confusion if a superpackage from another module is This also matches Java's definition of "enclosing elements," though I admit that I'm not sure how significant that usually is above the package level. This current approach can be inconvenient for users (as we've seen inside Google, for example), and we hope that some tools will offer a way to enforce that packages or classes are annotated with |
I will just add to what @cpovirk in that there is no such thing as a "subpackage" or "super package" in Java. The facilities to apparently navigate package trees at runtime in things like Spring are not really reliable in a compiler setting. It is sad that JPMS solves the problem but the uptake of it has been so poor. I'm perhaps overly optimistic but I'm hoping for a future for where that isn't the case. In an open source library IMO there is no excuse to not have package-info.java but I feel the pain for applications. @cpovirk one possible solution is to put something in META-INF similar to Automatic-Module-Name but I'm not sure how reliable retrieving that information is across tools. |
Interesting, I don't think we'd considered I guess there's also the principle that we want for the nullness specifications to be clear from the Java source files, without need to look at separate configuration files. (Ideally, we want it to be clear from looking at only the Java source file that you care about. But obviously we've felt it necessary to compromise there a little by supporting package-level and module-level defaulting at all. Even that leads to issues sometimes, since people will put |
I'm not really a fan of the My preferred solution as @dsyer can tell you is JPMS (its an ongoing joke we have that when this comes up I just say use modules 😄 ). |
Even more why I don't think In fact Eclipse (I'm like 1 of the 10 only people left that use it) will if null analysis is turned on warn you if miss not putting a NullMarked annotation of your choosing on a @NicklasWallgren are you using Eclipse or IntelliJ out of curiosity? |
Thanks for the link, which I admit I only skimmed after seeing you mention runtime concerns. So now, yikes, I'm afraid of runtime questions when looking for parent packages: If my classloader loads |
I think once JSpecify is released the tooling in IDEs will get better and enforce That is something like IntelliJ can just auto turn on create |
This thread has covered a lot of ground, but my impression is that the decision it represents is specifically that a package-level annotation will affect only that package (in that module) and no "subpackages" (which are not even a real concept in Java). If there was any other significant/debatable aspect please file separately. |
Current decision: JSpecify annotations on a Java package affect only symbols declared in that package, and not in "subpackages" (packages with a prefix that matches the annotated package). Argument for changing: It might be convenient for authors to annotate a number of packages with such a mechanism. However, Java does not consider packages to have any enclosing relationship with each other. As an alternative, module-level annotations do provide a way to apply an annotation to symbols in more than one package. Timing: This must be decided before version 1.0 of the spec. Proposal for 1.0: Finalize the current decision. If you agree, please add a thumbs-up emoji (👍) to this comment. If you disagree, please add a thumbs-down emoji (👎) to this comment and briefly explain your disagreement. Please only add a thumbs-down if you feel you can make a strong case why this decision will be materially worse for users or tool providers than an alternative. Results: Three 👍s; no other votemojis. |
Decision: JSpecify annotations on a Java package affect only symbols declared in that package, and not in "subpackages" (packages with a prefix that matches the annotated package). |
The question was initially raised by @amaembo:
cpovirk edit much later:
(See, for example, this question, these feature requests (IntelliJ, JDK, jOOQ), these StackOverflow questions (1, 2), and this behavior in the Checker Framework (and I want to say maybe some behavior in Spring?).)
The text was updated successfully, but these errors were encountered: