Skip to content
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

Support for @NotNullByDefault #2860

Open
enexusde opened this issue Feb 8, 2024 · 12 comments
Open

Support for @NotNullByDefault #2860

enexusde opened this issue Feb 8, 2024 · 12 comments

Comments

@enexusde
Copy link

enexusde commented Feb 8, 2024

I have a maven modul that contains DTOs only to encapsule the Single-Version-Of-Truth.

Since there is no LLOC Spotbugs thinks they are unused.

In order to not get an spotbugs-error I use @NonNull on all fields (org.codehaus.commons.nullanalysis.NotNull). This works great.

Since I need to annotate every single field with this annotation I tried to use org.codehaus.commons.nullanalysis.NotNullByDefault on the class in order to affect all fields in the class.

Unfortunately @NotNullByDefault does not cascade @NonNull to the class's fields.

But the javadoc points out:

By default, types in method signatures that lack a null annotation are regarded as nullable. This annotation (with it default value true) indicates that types in method signatures that lack a null annotation are regarded as non-null. It is generally good practice to add @NotNullByDefault to all your package declarations (i.e. 'package-into.java' files), because in well-designed code (especially API methods), @nonnull is significantly more frequent than @nullable.

Please:

  1. Support @NotNullByDefault on class-level
  2. Support @NotNullByDefault on package-info level
@enexusde
Copy link
Author

Hm, maybe I made a mistake. I use @nonnull on fields but the javadoc said on method-parameters.
Maybe close?

@gtoison
Copy link
Contributor

gtoison commented Feb 22, 2024

This is possibly related to #805

@gtoison
Copy link
Contributor

gtoison commented Feb 24, 2024

Have you tried org.eclipse.jdt.annotation.NonNullByDefault? There are references to it, so it seems to be supported

@enexusde
Copy link
Author

If I use the annotation I need to publish the sourcecode according to https://www.eclipse.org/legal/epl-2.0/

I can not do that!

@iloveeclipse
Copy link
Member

If I use the annotation I need to publish the sourcecode according to https://www.eclipse.org/legal/epl-2.0/

This is wrong. EPL 2.0 only requires to publisch modified EPL 2.0 code, so if you only use an EPL library, nothing needed to be published.

@enexusde
Copy link
Author

enexusde commented Feb 25, 2024

Please read again. At last if someone subclass the annotation we need to publish the subclass including the package, license and other organisational decisions. It forces company details to offer to the public clients are not willing to admit.

@enexusde
Copy link
Author

Support org.eclipse.jdt.annotation.NonNullByDefault but not support org.codehaus.commons.nullanalysis.NotNullByDefault, is up for debate in this ticket IMO.

@iloveeclipse
Copy link
Member

Sorry, you are still wrong, and don’t understand EPL.
The main purpose of EPL is to allow commercial use of applications built on top of EPL 2.0 software. The applications can use EPL based libraries without publishing its own code, and they only need to publish modified EPL code. This is done to make sure any improvements of the EPL code can fo back to the community without opening proprietery code. So you can extend classes or implement EPL interfaces as much as you can - the whole Eclipse story is based on that, and all of the major software companies do that without publishing their code! However, if you change EPL code, e.g. changes the annotation class for whatever reason, then you must make the changed code publicly available. However, even in this case you can separate changed code into a dedicated bundle and only publish that bundle, not your entire application.

@enexusde
Copy link
Author

enexusde commented Feb 25, 2024

Legal department said no EPL. Im no lawyer. Back to the debate?

@gtoison
Copy link
Contributor

gtoison commented Feb 26, 2024

I'm not sure what you want to debate, sure it would be nice if SpotBugs could support more ways to declare nullability, but at the end of the day this takes valuable time to contributors, on their free time.
The J2EE API is published under the EPL, it would be quite problematic if using the API required to publish your code. Your Legal is misunderstanding the EPL

@enexusde
Copy link
Author

Well, I think this ticket can be closed. You guys decide.

@gtoison
Copy link
Contributor

gtoison commented Feb 28, 2024

I don't think we're closing the door to supporting org.codehaus.commons.nullanalysis.NotNullByDefault, just trying to say that a reasonable alternative seems to exist already.
The project is a bit short on manpower and this type of improvement usually takes time. You can help by submitting a code sample illustrating your query.

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

No branches or pull requests

3 participants