Community
Participate
Working Groups
Eclipse 3.7M6: In the following code, at line 121 I'm seeing the warning "Potential null pointer access: The variable filePath may be null at this location" but at line 122 I'm seeing the warning "Redundant null check: The variable filePath cannot be null at this location". I believe the second warning is incorrect as filePath could still be null at this point. protected boolean computeChildren(OpenableInfo info, IProgressMonitor pm, IResource res) throws CModelException { ArrayList<ICElement> vChildren = new ArrayList<ICElement>(); IPath filePath = null; if (fPath != null) { filePath = fPath; } else if (fIncludeEntry != null) { filePath = fIncludeEntry.getFullIncludePath(); } 121 System.out.println("computeChildren: "+ filePath.toString()); 122 if (filePath != null) { if (!filePath.isUNC()) { File file = filePath.toFile(); String[] names = null; if (file != null && file.isDirectory()) { names = file.list(); if (names != null) { IPath path = new Path(file.getAbsolutePath()); for (String name : names) { File child = new File(file, name); ICElement celement = null; if (child.isDirectory()) { celement = new IncludeReference(this, fIncludeEntry, new Path(child.getAbsolutePath())); } else if (child.isFile()){ String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), name); if (id != null) { // TODO: should use URI celement = new ExternalTranslationUnit(this, URIUtil.toURI(path.append(name)), id); } } if (celement != null) { vChildren.add(celement); } } } } } else { try { IFileStore store = EFS.getStore(URIPathConverter.toURI(filePath)); IFileStore children[] = store.childStores(EFS.NONE, pm); for (IFileStore child : children) { ICElement celement = null; if (child.fetchInfo().isDirectory()) { celement = new IncludeReference(this, fIncludeEntry, filePath.append(child.getName())); } else { String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), child.getName()); if (id != null) { // TODO: should use URI celement = new ExternalTranslationUnit(this, child.toURI(), id); } } if (celement != null) { vChildren.add(celement); } } } catch (CoreException e) { } } } info.setChildren(vChildren); return true; }
Both warnings are correct. The potential NPE in line 121 is because the value assigned to filePath from fIncludeEntry.getFullIncludePath() may be null. Again, at line 122, filePath can no longer be null. If it were null, line 121 would've thrown an NPE and the program would've exited. Hence, in no scenario can filepath still be null if line 122 is reached. Closing as invalid.
Verified for 3.7 M7