-
Notifications
You must be signed in to change notification settings - Fork 455
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
Java - Improper warning - Potential null pointer access #3124
Comments
@ravindragullapalli I can't reproduce the issue. |
@snjeza Please find the attached file. Hope this helps |
Added another method nullTest3 where I am not getting that Potential Null Pointer Access. Please find attached zip file. |
Null check will also get misleading result in Assert.notNull scenary, here is an another example code snippet: import javax.annotation.Nullable;
@Data
public class Request<T> {
@Nullable
private T data;
}
public class PageMonitorConfigController {
@GetMapping("/xxx")
public Object doSth (@RequestBody Request<Sth> req) {
Assert.notNull(pageableRequest.getData(), "data is null");
// got 'Potential null pointer access' here ⬇️
java.lang.System.out.println(pageableRequest.getData().getContent());
return "done";
}
} AFAK, Intellj idea provides an annotation |
also with AssertJ: @SuppressWarnings("unchecked")
ResponseEntity<Response> castedResult = (ResponseEntity<Response>)result.getResult();
assertThat(castedResult).isNotNull();
assertThat(castedResult.getStatusCode()).isEqualTo(HttpStatus.OK);
|
This issue is marked with "upstream". It seems @snjeza has fixed this issue in the eclipse.jdt.core project in the middle of December 2023, see mentioned issue. What needs to be done to have this fix in the vscode-java extension? |
AFAICT it's already fixed in vscode-java, but the issue was not closed. I can't reproduce the issue with @ravindragullapalli's test project. Else I'll close this issue. |
I can't reproduce it with the exact same code either. So, yes it's fixed and the issue can be closed. |
I can confirm that I am not getting this warning now. Thank you for fixing it. |
In Java, Visual Studio Code is not recognizing "Objects.isNull" check statement while giving warning of Potential null pointer access (Java 536871364).
Environment
Steps To Reproduce
For example, if the code is like
However, if I do this the warning disappears
Current Result
"Potential null pointer access: The variable obj may be null at this locationJava(536871364)" warning is displayed
Expected Result
No warning should be there as null check is already done using
Objects.isNull
Additional Informations
The text was updated successfully, but these errors were encountered: