113

I have seen the question JSR305 vs. JSR308 (Java Type Anotations) - Which is going to be the standard? and I understand the difference between JSR 308 and JSR 305.

I also understand that, at this time, 308 is slated for Java 7, and 305 is not, and I am curious about the overall status of 305.

Specifically, I am using Google Collections and JSR-305 in some of my projects (in a similar manner to what one of the Guice best practices advocates) and was wondering if there is a more "future direction"-friendly approach I should be using instead. I am planning to also ask about this on the JSR-305 group, but that group does not have much activity and I was just wondering if anyone here had any more info.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Charlie Collins
  • 8,806
  • 4
  • 32
  • 41
  • 1
    I would accept the answer you left Kevin, but I can't find a place in those articles where it says definitively they will be in Java 7, or not? (And I had reviewed that info, briefly, before posting the question actually.) Did you see a specific mention in there that they *will* be included (as indicated in your answer)? Thanks in advance for your help. – Charlie Collins Feb 22 '10 at 21:37
  • 1
    After this much time, and some other efforts to figure out exactly what's up, I'm awarding the best answer, the only answer, the "answer" distinction. ;) – Charlie Collins May 27 '10 at 16:21
  • Java 9: https://stackoverflow.com/questions/37598775/jsr-305-annotations-replacement-for-java-9 – Christophe Roussy Feb 13 '18 at 16:59
  • Mark Reinhold [recently commented on another SO post that](https://stackoverflow.com/questions/4963300/which-notnull-java-annotation-should-i-use#comment90023610_42695253) "JSR 305, which would’ve standardized javax.annotation.NonNull, never completed because its spec lead went AWOL." – Flow Apr 08 '19 at 10:40

5 Answers5

82

As described in this answer, JSR-305 proposes new annotations such as @NonNull, while JSR-308 proposes allowing annotations in new places such as on generic declarations.

Quoting JSR 308 page:

…this document does not propose any annotations, merely specifying where they can appear in Java code.

JSR 308 (annotations in new places) is included in java 8 under JEP 104.

As of 2017, JSR 305 (new annotations) continues to carry official status of “Dormant”. A question about it's status in the google group has been unanswered since 2010.

There is a reference implementation of the JSR-305 annotations here which is used by many projects, including guava. With maven you can use the JSR-305 reference implementation by adding this to your pom:

<dependency>
    <groupId>com.google.code.findbugs</groupId>
    <artifactId>jsr305</artifactId>
    <version>3.0.0</version>
</dependency>
Naman
  • 27,789
  • 26
  • 218
  • 353
sbridges
  • 24,960
  • 4
  • 64
  • 71
  • 2
    link to [com.google.code.findbugs:jsr305 on maven central](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22com.google.code.findbugs%22%20AND%20a%3A%22jsr305%22) (latest version is now 3.0.0) – Paolo Fulgoni Jul 23 '14 at 16:35
  • You can use the same version as for the `findbugs-maven-plugin` (from `org.codehaus.mojo`) to sync both. – Christophe Roussy Jan 22 '15 at 09:35
  • 2
    Java 9 is feature complete but not released, and it looks as though JSR-305 is not included. Was there another JSR that added similar annotations? – dlamblin Nov 30 '16 at 02:08
21

JSR 305 will not be part of Java 8:

11

If you are concerned about nullability annotations then I would recommend using the ones provided by SpotBugs project from the edu.umd.cs.findbugs.annotations namespace. These days it should be supported by most linters or IDEs. It's not as nice as proposed javax.annotation in JSR 305, but remember that JSR 305 was never approved and actually no jar file with classes was ever attached to JSR 305 proposal.

Few more interesting articles regarding this:

JSR 305 vs JSR 308

There is barely any relation between JSR 305 and JSR 308. JSR 308 is about ability to apply annotations to generics (java type arguments). JSR 308 has been incorporated as part of Java SE 8.

The only link is that both JSRs are related to a two distinct projects (FindBugs and Checker Framework) which are touching null-safety and nullability annotations topic.

By content the JSRs are no way related.

mancze
  • 669
  • 6
  • 22
10

Java 8 is described by JSR 337: the specification has reached Final status: see here.

  • JSR 308 is definitely in
  • JSR 305 is definitely out
Glen Best
  • 22,769
  • 3
  • 58
  • 74
1

According to Alex Millers Java 7 blog, JSR-308 (and 305) are scheduled to go in to Java 7. Perhaps he will show up here and give you more information.

Kevin
  • 30,111
  • 9
  • 76
  • 83