Bug 283123

Summary: Errors/Warnings indicator shows wrong "dead code"!
Product: [Eclipse Project] JDT Reporter: MH <mhilpert>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: VERIFIED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, srikanth_sankaran
Version: 3.5   
Target Milestone: 3.6 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description MH CLA 2009-07-10 05:37:28 EDT
Build ID: 20090619-0625

Steps To Reproduce:
Eclipse shows in a Java source file an indicator "dead code" for Java source code that is completely valid and has no dead code:

    /**
     * Get first node with a specific name.
     * 
     * @param document Documentto search.
     * @param name Name of (first) node to return.
     * @return First node found or null if no node found.
	 */
	static public Node getFirstNode(final Document document, final String name) {
        Node result = null;
        
        if (document != null && name != null) {
            final NodeList nodeList = document.getElementsByTagName(name);
            final int count = nodeList.getLength();
            for (int i = 0; i < count; i++) {
                result = nodeList.item(i);
                break; //only first node
            }//next node
        }//else: input unavailable
        
        return result;
    }//getFirstNode()

The "i++" in the line

  for (int i = 0; i < count; i++) {

is marked as "dead code" which is of course not true. Strangly, other similar code with such loops are not marked.


More information:
It always shows this marker - no matter if I restart Eclipse, compile, clean, etc.
Comment 1 Frederic Fusier CLA 2009-07-10 09:26:03 EDT
It looks to me that this warning is appropriate due to the break; line in the loop. This line makes the i incrementation is never done, hence the compiler warning...
Comment 2 Srikanth Sankaran CLA 2009-08-04 06:01:16 EDT
Verified for 3.6M1