simplemagic icon indicating copy to clipboard operation
simplemagic copied to clipboard

Request: add nullable annotations, to know what can return null

Open AndroidDeveloperLB opened this issue 2 years ago • 3 comments

For example, I've noticed there is some case that "findMatch" can return null:

private ContentInfo findMatch(byte[] bytes, List<MagicEntry> entryList) {
    ....
    if (partialMatchInfo == null) {
        logger.trace("returning no match");
            return null;z

AndroidDeveloperLB avatar Sep 24 '23 00:09 AndroidDeveloperLB

I'm not sure I understand your question. It is returning null because it found no match to the bytes. Are you asking for partial match information or something? Can you provide an example and what output you would like?

j256 avatar Oct 04 '23 12:10 j256

If I understand the title correctly, it is a request to annotate public methods with JSR 305 @Nullable and @Nonnull

vinceh121 avatar Oct 04 '23 14:10 vinceh121

@j256 Nullability annotations help both the IDE and us to understand which functions can return null and which function should never return null. This helps with prevention of NPE, helps the IDE to offer various optimizations, helps to remove useless nullability checks, and also provides better support for Kotlin which forces developers to declare what can have a null value and what cannot.

AndroidDeveloperLB avatar Oct 04 '23 22:10 AndroidDeveloperLB