Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Optional emptiness handler (#278)
Added Optional Emptiness handler which does couple of things 1. on `optionalFoo.get()` hints that it can be Nullable. 2. on `optionalFoo.isPresent()` sets the `optionalFoo.get()` access path to Non-null. This allows ``` if (fooOptional.isPresent()) { fooOptional.get().bar(); // Implicitly understood to be safe } ``` and returns a warning if not implied safe. Fixes #274 Added unit tests Handler is gated by a configuration flag.
- Loading branch information
1 parent
baf7fbb
commit 4a4b591
Showing
17 changed files
with
395 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
nullaway/src/main/java/com/uber/nullaway/ErrorMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.uber.nullaway; | ||
|
||
/** Contains error message string to be displayed and the message type from {@link MessageTypes}. */ | ||
public class ErrorMessage { | ||
MessageTypes messageType; | ||
String message; | ||
|
||
ErrorMessage(MessageTypes messageType, String message) { | ||
this.messageType = messageType; | ||
this.message = message; | ||
} | ||
|
||
public void updateErrorMessage(MessageTypes messageType, String message) { | ||
this.messageType = messageType; | ||
this.message = message; | ||
} | ||
|
||
public enum MessageTypes { | ||
DEREFERENCE_NULLABLE, | ||
RETURN_NULLABLE, | ||
PASS_NULLABLE, | ||
ASSIGN_FIELD_NULLABLE, | ||
WRONG_OVERRIDE_RETURN, | ||
WRONG_OVERRIDE_PARAM, | ||
METHOD_NO_INIT, | ||
FIELD_NO_INIT, | ||
UNBOX_NULLABLE, | ||
NONNULL_FIELD_READ_BEFORE_INIT, | ||
ANNOTATION_VALUE_INVALID, | ||
CAST_TO_NONNULL_ARG_NONNULL, | ||
GET_ON_EMPTY_OPTIONAL; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.