Bug 546745 - Annotation based null analysis fails in try finally when used in loop
Summary: Annotation based null analysis fails in try finally when used in loop
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.11   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-25 10:56 EDT by Roland Praml CLA
Modified: 2023-05-07 14:56 EDT (History)
0 users

See Also:


Attachments
Screenshot-of-example (44.53 KB, image/png)
2019-04-25 10:56 EDT, Roland Praml CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Roland Praml CLA 2019-04-25 10:56:20 EDT
Created attachment 278398 [details]
Screenshot-of-example

I found the following issue, that a possible NPE is not reported when the code is in a finally statement and a loop is involved.

How to reproduce:

- Create a new project
- enable annotation based NPE (http://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftask-using_null_annotations.htm)
- take this example code
-----------------
import java.util.Arrays;
import java.util.List;

import org.eclipse.jdt.annotation.Nullable;

public class NullDemo {

  @Nullable
  private String getNull() {
    return null;
  }

  public void testInLoop() {
    List<Integer> arr = Arrays.asList(1, 2, 3);
    for (Integer elem : arr) {
      try {
        System.out.println(elem);
        String s1 = getNull();
        s1.toString(); // marked as potential NPE

      } finally {
        String s2 = getNull();
        s2.toString(); // NOT marked as potential NPE
      }
      String s3 = getNull();
      s3.toString(); // marked as potential NPE
    }
  }
  
  public void testWithoutLoop() {
	while (true)  {
    try {
    } catch (Exception e) {
      String s1 = getNull();
      s1.toString(); // marked as potential NPE

    } finally {
      String s2 = getNull();
      s2.toString(); // marked as potential NPE
    }
    String s3 = getNull();
    s3.toString(); // marked as potential NPE
  }
  }
}

-----------------

See the screenshot. The blue bordered line should be marked as possible NPE, too.

cheers
Roland
Comment 1 Eclipse Genie CLA 2021-04-15 15:13:20 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Eclipse Genie CLA 2023-05-07 14:56:19 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.