Fixed NullPointerException (problems == null) may occur
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / builder / AbstractImageBuilder.java
index d60ea71..e1858c7 100644 (file)
@@ -87,52 +87,52 @@ public abstract class AbstractImageBuilder implements ICompilerRequestor {
 
     SourceFile compilationUnit = (SourceFile) result.getCompilationUnit(); // go directly back to the sourceFile
     if (!workQueue.isCompiled(compilationUnit)) {
-//      try {
-        workQueue.finished(compilationUnit);
-        try {
-                       updateProblemsFor(compilationUnit, result); // record compilation problems before potentially adding duplicate errors
-                       updateTasksFor(compilationUnit, result); // record tasks 
-               } catch (CoreException e) {
-                       throw internalException(e);
-               } 
-               
-        // String typeLocator = compilationUnit.typeLocator();
-        //                     ClassFile[] classFiles = result.getClassFiles();
-        //                     int length = classFiles.length;
-        //                     ArrayList duplicateTypeNames = null;
-        //                     ArrayList definedTypeNames = new ArrayList(length);
-        //                     for (int i = 0; i < length; i++) {
-        //                             ClassFile classFile = classFiles[i];
-        //                             char[][] compoundName = classFile.getCompoundName();
-        //                             char[] typeName = compoundName[compoundName.length - 1];
-        //                             boolean isNestedType = CharOperation.contains('$', typeName);
-        //
-        //                             // Look for a possible collision, if one exists, report an error but do not write the class file
-        //                             if (isNestedType) {
-        //                                     String qualifiedTypeName = new String(classFile.outerMostEnclosingClassFile().fileName());
-        //                                     if (newState.isDuplicateLocator(qualifiedTypeName, typeLocator))
-        //                                             continue;
-        //                             } else {
-        //                                     String qualifiedTypeName = new String(classFile.fileName()); // the qualified type name "p1/p2/A"
-        //                                     if (newState.isDuplicateLocator(qualifiedTypeName, typeLocator)) {
-        //                                             if (duplicateTypeNames == null)
-        //                                                     duplicateTypeNames = new ArrayList();
-        //                                             duplicateTypeNames.add(compoundName);
-        //                                             createErrorFor(compilationUnit.resource, ProjectPrefUtil.bind("build.duplicateClassFile", new String(typeName)));
-        // //$NON-NLS-1$
-        //                                             continue;
-        //                                     }
-        //                                     newState.recordLocatorForType(qualifiedTypeName, typeLocator);
-        //                             }
-        //                             definedTypeNames.add(writeClassFile(classFile, compilationUnit.sourceLocation.binaryFolder, !isNestedType));
-        //                     }
-
-        //                     finishedWith(typeLocator, result, compilationUnit.getMainTypeName(), definedTypeNames, duplicateTypeNames);
-        notifier.compiled(compilationUnit);
-//      } catch (CoreException e) {
-//        Util.log(e, "JavaBuilder handling CoreException"); //$NON-NLS-1$
-//        createErrorFor(compilationUnit.resource, Util.bind("build.inconsistentClassFile")); //$NON-NLS-1$
-//      }
+      //      try {
+      workQueue.finished(compilationUnit);
+      try {
+        updateProblemsFor(compilationUnit, result); // record compilation problems before potentially adding duplicate errors
+        updateTasksFor(compilationUnit, result); // record tasks
+      } catch (CoreException e) {
+        throw internalException(e);
+      }
+
+      // String typeLocator = compilationUnit.typeLocator();
+      //                       ClassFile[] classFiles = result.getClassFiles();
+      //                       int length = classFiles.length;
+      //                       ArrayList duplicateTypeNames = null;
+      //                       ArrayList definedTypeNames = new ArrayList(length);
+      //                       for (int i = 0; i < length; i++) {
+      //                               ClassFile classFile = classFiles[i];
+      //                               char[][] compoundName = classFile.getCompoundName();
+      //                               char[] typeName = compoundName[compoundName.length - 1];
+      //                               boolean isNestedType = CharOperation.contains('$', typeName);
+      //
+      //                               // Look for a possible collision, if one exists, report an error but do not write the class file
+      //                               if (isNestedType) {
+      //                                       String qualifiedTypeName = new String(classFile.outerMostEnclosingClassFile().fileName());
+      //                                       if (newState.isDuplicateLocator(qualifiedTypeName, typeLocator))
+      //                                               continue;
+      //                               } else {
+      //                                       String qualifiedTypeName = new String(classFile.fileName()); // the qualified type name "p1/p2/A"
+      //                                       if (newState.isDuplicateLocator(qualifiedTypeName, typeLocator)) {
+      //                                               if (duplicateTypeNames == null)
+      //                                                       duplicateTypeNames = new ArrayList();
+      //                                               duplicateTypeNames.add(compoundName);
+      //                                               createErrorFor(compilationUnit.resource, ProjectPrefUtil.bind("build.duplicateClassFile", new String(typeName)));
+      // //$NON-NLS-1$
+      //                                               continue;
+      //                                       }
+      //                                       newState.recordLocatorForType(qualifiedTypeName, typeLocator);
+      //                               }
+      //                               definedTypeNames.add(writeClassFile(classFile, compilationUnit.sourceLocation.binaryFolder, !isNestedType));
+      //                       }
+
+      //                       finishedWith(typeLocator, result, compilationUnit.getMainTypeName(), definedTypeNames, duplicateTypeNames);
+      notifier.compiled(compilationUnit);
+      //      } catch (CoreException e) {
+      //        Util.log(e, "JavaBuilder handling CoreException"); //$NON-NLS-1$
+      //        createErrorFor(compilationUnit.resource, Util.bind("build.inconsistentClassFile")); //$NON-NLS-1$
+      //      }
     }
   }
 
@@ -361,13 +361,12 @@ public abstract class AbstractImageBuilder implements ICompilerRequestor {
 
       /*
        * Do NOT want to populate the Java Model just to find the matching Java element. Also cannot query compilation units located
-       * in folders with invalid package names such as 'a/b.c.d/e'.
-       *  // compute a user-friendly location IJavaElement element = JavaCore.create(resource); if (element instanceof
-       * net.sourceforge.phpdt.core.ICompilationUnit) { // try to find a finer grain element
-       * net.sourceforge.phpdt.core.ICompilationUnit unit = (net.sourceforge.phpdt.core.ICompilationUnit) element; IJavaElement
-       * fragment = unit.getElementAt(problem.getSourceStart()); if (fragment != null) element = fragment; } String location = null;
-       * if (element instanceof JavaElement) location = ((JavaElement) element).readableName(); if (location != null)
-       * marker.setAttribute(IMarker.LOCATION, location);
+       * in folders with invalid package names such as 'a/b.c.d/e'. // compute a user-friendly location IJavaElement element =
+       * JavaCore.create(resource); if (element instanceof net.sourceforge.phpdt.core.ICompilationUnit) { // try to find a finer
+       * grain element net.sourceforge.phpdt.core.ICompilationUnit unit = (net.sourceforge.phpdt.core.ICompilationUnit) element;
+       * IJavaElement fragment = unit.getElementAt(problem.getSourceStart()); if (fragment != null) element = fragment; } String
+       * location = null; if (element instanceof JavaElement) location = ((JavaElement) element).readableName(); if (location !=
+       * null) marker.setAttribute(IMarker.LOCATION, location);
        */
 
       //               if (missingClassFile != null)
@@ -414,10 +413,12 @@ public abstract class AbstractImageBuilder implements ICompilerRequestor {
     if (problems == null || problems.length == 0)
       return;
     //axelcl start insert - calculate line numbers
-    for (int i = 0; i < problems.length; i++) {
-      if (problems[i].getSourceLineNumber() == 1) {
-        problems[i].setSourceLineNumber(ProblemHandler
-            .searchLineNumber(result.lineSeparatorPositions, problems[i].getSourceStart()));
+    if (problems != null) {
+      for (int i = 0; i < problems.length; i++) {
+        if (problems[i].getSourceLineNumber() == 1) {
+          problems[i].setSourceLineNumber(ProblemHandler.searchLineNumber(result.lineSeparatorPositions, problems[i]
+              .getSourceStart()));
+        }
       }
     }
     //axelcl end insert