Bug 132875 - [compiler][null][pattern] recognize System.exit() as non returning
Summary: [compiler][null][pattern] recognize System.exit() as non returning
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P5 major with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 193972 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-03-22 13:16 EST by Eugene Kuleshov CLA
Modified: 2020-04-21 05:26 EDT (History)
8 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Kuleshov CLA 2006-03-22 13:16:38 EST
Null reference analyzer raizing a false positive on the following code:

  public static void main(String[] args) {
    String v = System.getProperty("test");
    if(v==null) {
      System.exit(0);
    }
    if(!v.startsWith("a")) {
      System.err.println("### B.main() "+v);
    }
  }

  Basically System.exit() here should have the same effect as return or trow.
Comment 1 Philipe Mulet CLA 2006-03-23 09:32:51 EST
Not really if you follow the standard rules for definite assignment etc...
System.exit(...) is just another message send.

The nullref analysis is consistent with our conservative data flow analysis in this respect.
Comment 2 Philipe Mulet CLA 2006-03-23 09:34:41 EST
If you want to make it obvious to the compiler, then write:

  public static void main(String[] args) {
    String v = System.getProperty("test");
    if(v==null) {
      System.exit(0);
      return; // cannot be reached for real due to #exit(...) call
    }
    if(!v.startsWith("a")) {
      System.err.println("### B.main() "+v);
    }
  }
Comment 3 Eugene Kuleshov CLA 2006-03-23 10:14:29 EST
(In reply to comment #2)
Philippe, I don't think it is acceptable to add return after System.exit(). I'd agree that using system.exit() in first place is moveton, but this particular warning appeared in some legacy code I am not allowed to touch and yet I see this warning. I believe it is reasonable to take into account that stis call can terminate JVM execution.
Comment 4 Maxime Daniel CLA 2006-03-24 04:12:03 EST
This might well imply a separation between the current flow analysis and the null flow analysis, which is due to be expensive at runtime. Currently, the null analysis leverages the knowledge the flow analysis has of dead branches. But the latter is commanded by the JLS, which is fairly conservative and doesn't know about System.exit(). This hence implies that we introduce 'null only dead branches', and recraft the whole logic. I would rather not do this without considering other needs for refactoring as well.
Comment 5 Maxime Daniel CLA 2006-04-25 00:47:34 EDT
Post 3.2.
Comment 6 Maxime Daniel CLA 2006-09-26 08:53:02 EDT
Since this one is due to be expensive, I'd rather leave it to more comprehensive static analysis tools and close it as WONTFIX.

Philippe, what do you think?
Comment 7 Maxime Daniel CLA 2007-06-19 08:07:05 EDT
Reopening as P5 (since RESOLVED LATER is deprecated).
Comment 8 Maxime Daniel CLA 2007-06-22 11:28:20 EDT
*** Bug 193972 has been marked as a duplicate of this bug. ***
Comment 9 Philipp Stevermann CLA 2008-10-24 17:45:53 EDT
(In reply to comments 4,5 and 6)
How about adding System.exit(), Runtime.getRuntime().exit() and Runtime.getRuntime().halt() as always throwing an exception to the normal flow analysis, marking code behind calls as dead code? The assertion that these methods methods don't return normally should be true for the foreseeable future.
Comment 10 Jari Juslin CLA 2009-07-16 08:02:45 EDT
API specification from Sun specifies clearly that System.exit never returns normally: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html#exit(int)

In addition to this, there is no way to return a specific error code and exit the JVM, so you can't really replace the System.exit() calls with something else.

So in light on these, System.exit() should have just the same effect as throw.
Comment 11 Johan Walles CLA 2010-02-04 09:57:18 EST
This problem makes the "potential null pointer access" warning give false positives.

Switching off that warning for now and adding my vote:
https://bugs.eclipse.org/bugs/votes.cgi?action=show_user&bug_id=132875#vote_132875
Comment 12 Omry Yadan CLA 2013-05-07 02:32:23 EDT
Eclipse really lost the momentum.
After encountering this bug, I somehow knew there is already a bug open for it. and I somehow knew no one gives a shit.
the bug is now over 7 years old.
Comment 13 Eclipse Genie CLA 2020-04-21 05:26:43 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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.