Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-patch] Fix for NPE in CProjectSourceLocation

Hi,

I have another small patch that fixes an NPE we've seen with CDT source
locators. 

Basically, the steps to reproduce are:
- create a CDT project (e.g. managed make C). Build
- add an additional source location. Run or debug project.
- Delete the project
- Hit the running man/bug to run/debug last project (i.e rerun from
history without allowing launch config gui to update the launch
configuration)
- User gets an error dialog reporting an internal error, saying to look
in error log for details
- Error log has a NPE. 

The fix involved checking for null after a getLocation() function, which
was returning null as the project folders no longer existed. Applying
this fix means that the GUI then correctly reports that the project is
invalid without falling over before hand. 

The patch should be applied on the CProjectSourceLocation.java file in
org.eclipse.cdt.debug.internal.core.sourcelookup package.  This patch
was verified with CDT 2.1.1 though the file in question has not been
modified at all for CDT 3.0.0.

Again, if you find this patch is straightforward and very low-risk, may
we have it applied to both the HEAD and the 2.1.1 branch for the
upcoming release build.

Thanks,
Tracy Miranda
Altera European Technology Centre (ETC)
 <<CProjectSourceLocation.txt>> 
Index: CProjectSourceLocation.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt-debug/org.eclipse.cdt.debug.core/src/org/eclipse/cdt/debug/internal/core/sourcelookup/CProjectSourceLocation.java,v
retrieving revision 1.24
diff -u -r1.24 CProjectSourceLocation.java
--- CProjectSourceLocation.java	25 Jun 2004 14:47:08 -0000	1.24
+++ CProjectSourceLocation.java	24 Feb 2005 14:39:10 -0000
@@ -186,18 +186,21 @@
 		{
 			if ( list.size() > 0 && !searchForDuplicateFiles() )
 				break;
-			IPath path = folders[i].getLocation().append( fileName );
-			File file = new File( path.toOSString() );
-			if ( file.exists() )
-			{
-				IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path );
-				for ( int j = 0; j < wsFiles.length; ++j )
-					if ( wsFiles[j].exists() )
-					{
-						if ( !searchForDuplicateFiles() )
-							return wsFiles[j];
-						list.add( wsFiles[j] );
-					}
+			IPath location = folders[i].getLocation();
+			if (location != null) {
+				IPath path = location.append( fileName );
+				File file = new File( path.toOSString() );
+				if ( file.exists() )
+				{
+					IFile[] wsFiles = CDebugCorePlugin.getWorkspace().getRoot().findFilesForLocation( path );
+					for ( int j = 0; j < wsFiles.length; ++j )
+						if ( wsFiles[j].exists() )
+						{
+							if ( !searchForDuplicateFiles() )
+								return wsFiles[j];
+							list.add( wsFiles[j] );
+						}
+				}
 			}
 		}
 		return ( list.size() > 0 ) ? ( ( list.size() == 1 ) ? list.getFirst() : list ) : null;

Back to the top