Community
Participate
Working Groups
Build Identifier: 20110218-0911 Eclipse is reporting null code on else-if branches when null checks are used. Example: the following code reports dead on the second else-if branch and the else branch: static Filter locateAndParse(File dir) throws IOException { final File includesFile = new File(dir.getPath() + "/includes"); final File excludesFile = new File(dir.getPath() + "/excludes"); if (includesFile != null && excludesFile != null) { throw new IOException(String.format("Directory %s has both an 'includes' and an 'excludes' file: remove one or both", dir)); } else if (includesFile != null) { return createIncludes(parseFile(includesFile)); } else if (excludesFile != null) { return createExcludes(parseFile(excludesFile)); } else { return createAllPass(); } } Now, substituting the xxxFile != null with a boolean hasXxx that has been assigned from the non-null check fixes it. static Filter locateAndParseX(File dir) throws IOException { final File includesFile = new File(dir.getPath() + "/includes"); final File excludesFile = new File(dir.getPath() + "/excludes"); final boolean hasIncludes = includesFile != null; final boolean hasExcludes = excludesFile != null; if (hasIncludes && hasExcludes) { throw new IOException(String.format("Directory %s has both an 'includes' and an 'excludes' file: remove one or both", dir)); } else if (hasIncludes) { return createIncludes(parseFile(includesFile)); } else if (hasExcludes) { return createExcludes(parseFile(excludesFile)); } else { return createAllPass(); } } The second method is semantically the same as the first. The only differences is instead of non-null checks, I've substituted booleans. If the first method complains, so should the second one. Reproducible: Always Steps to Reproduce: 1. Open Java editor - create a new class. 2. Add two static methods as described in 'Details' 3. Method 1 will complain with "dead code", while method 2 will not complain. The two methods are equivalent.
NOT A BUG. Realised that file is always not null
Verified for 3.7 RC1