redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 433 forks source link

Potential null pointer access #3695

Open Faputa opened 2 months ago

Faputa commented 2 months ago

Type: Bug

assert != null not working

image

image

Extension version: 1.32.0 VS Code version: Code 1.91.0 (ea1445cc7016315d0f5728f8e8b12a45dc0a7286, 2024-07-01T18:52:22.949Z) OS version: Windows_NT x64 10.0.19045 Modes:

System Info |Item|Value| |---|---| |CPUs|AMD Ryzen 5 PRO 4650U with Radeon Graphics (12 x 2096)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|15.23GB (4.52GB free)| |Process Argv|--crash-reporter-id f5996097-ae46-4ad3-8875-a294c592650a| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv368cf:30146710 vspor879:30202332 vspor708:30202333 vspor363:30204092 vswsl492:30256859 vscorecescf:30445987 vscod805:30301674 binariesv615:30325510 vsaa593:30376534 py29gd2263:31024239 c4g48928:30535728 azure-dev_surveyone:30548225 a9j8j154:30646983 962ge761:30959799 pythongtdpath:30769146 pythonnoceb:30805159 asynctok:30898717 pythonregdiag2:30936856 pythonmypyd1:30879173 h48ei257:31000450 pythontbext0:30879054 dsvsc016:30899300 dsvsc017:30899301 dsvsc018:30899302 cppperfnew:31000557 dsvsc020:30976470 pythonait:31006305 jchc7451:31067544 dsvsc021:30996838 f3je6385:31013174 pythoncenvpt:31062603 a69g1124:31058053 dvdeprecation:31068756 dwnewjupyter:31046869 legacy_priority:31082724 ```
speedythesnail commented 2 months ago

I also have this issue. VS Code 1.91.0 JDK: OpenJDK 17.0.12 2024-07-16 LTS Extension version: 1.32.0

Code Samples being incorrectly flagged:

return podList.stream()
  .filter(Objects::nonNull)
  .filter(pod -> pod.getSpec() != null && pod.getSpec().getVolumes() != null)
  .filter(pod -> pod.getSpec().getVolumes().stream() // This warns of potential null pointer
   //  ... rest of filter here
  )
  .collect(Collectors.toList());
}

Another Code sample:

public Quantity getPvcMaxSize(V1PersistentVolumeClaim pvc) {
  if (pvc.getSpec() == null) {
    throw new InvalidPvcSpecException();
  }

  if(pvc.getSpec().getResources() == null) { // Incorrectly marks pvc.getSpec() as potential null pointer
    throw new InvalidResourcesException();
  }

  // .. More code here
}