https://github.com/rinpatch/nullanalyzer
A static analyzer for Java using javaparser, that tracks null status of in-method variables and warns of redundant/wrong code related to it. Done as a coding task for Jetbrains Verification or Program Analysis Lab internship.
https://github.com/rinpatch/nullanalyzer
Last synced: about 1 year ago
JSON representation
A static analyzer for Java using javaparser, that tracks null status of in-method variables and warns of redundant/wrong code related to it. Done as a coding task for Jetbrains Verification or Program Analysis Lab internship.
- Host: GitHub
- URL: https://github.com/rinpatch/nullanalyzer
- Owner: rinpatch
- License: wtfpl
- Created: 2022-02-26T19:12:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-02-28T12:10:09.000Z (over 4 years ago)
- Last Synced: 2025-02-04T11:43:41.220Z (over 1 year ago)
- Language: Kotlin
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NullAnalyzer
## Limitations
The analyzer does not currently track the status of fields.
So, for example the following code should not produce errors, but will:
```java
void foo(@NotNull Point p) {
}
void test(@NotNull Point p) {
if (p.rightNeighbour != null){
foo(p.rightNeighbour)
}
}
```
## Building
```sh
gradle jar
```
## Usage
```sh
java -jar build/libs/NullAnalyzer-1.0-SNAPSHOT.jar example.java out.json
```
## Example output
```json
[
{
"line": 14,
"type": "REDUNDANT_NULL_CHECK",
"offendingCode": "nonNullP == null"
},
{
"line": 18,
"type": "FUNCTION_CALL_MAY_BE_NULL",
"offendingCode": "foo(nullP)"
},
{
"line": 25,
"type": "FIELD_ACCESS_MAY_BE_NULL",
"offendingCode": "nullP.x"
},
{
"line": 37,
"type": "FIELD_ACCESS_IS_NULL",
"offendingCode": "defaultP.x"
},
{
"line": 43,
"type": "FUNCTION_CALL_MAY_BE_NULL",
"offendingCode": "foo(defaultP)"
}
]
```