You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2019/11/07 22:07:01 UTC

[royale-compiler] branch develop updated: EmbedCompilationUnit: avoid null reference exception when base class is missing

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new d86a6da  EmbedCompilationUnit: avoid null reference exception when base class is missing
d86a6da is described below

commit d86a6dadfae13f0e456ec69c47da2aa28324ca01
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Nov 7 14:06:53 2019 -0800

    EmbedCompilationUnit: avoid null reference exception when base class is missing
---
 .../compiler/internal/units/EmbedCompilationUnit.java   | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/units/EmbedCompilationUnit.java b/compiler/src/main/java/org/apache/royale/compiler/internal/units/EmbedCompilationUnit.java
index abf190c..96ab8b3 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/units/EmbedCompilationUnit.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/units/EmbedCompilationUnit.java
@@ -51,6 +51,7 @@ import org.apache.royale.compiler.internal.units.requests.SyntaxTreeRequestResul
 import org.apache.royale.compiler.problems.ICompilerProblem;
 import org.apache.royale.compiler.problems.InvalidABCByteCodeProblem;
 import org.apache.royale.compiler.problems.NoScopesInABCCompilationUnitProblem;
+import org.apache.royale.compiler.problems.UnknownSuperclassProblem;
 import org.apache.royale.compiler.scopes.IASScope;
 import org.apache.royale.compiler.tree.as.IASNode;
 import org.apache.royale.compiler.units.ICompilationUnit;
@@ -310,9 +311,19 @@ public class EmbedCompilationUnit extends CompilationUnitBase
         if (embedData.generatedClassExtendsAnother())
         {
             ASProjectScope projectScope = getProject().getScope();
-            IDefinition[] defs = projectScope.findAllDefinitionsByName(Multiname.crackDottedQName(getProject(), embedData.getTranscoder().getBaseClassQName()));
-            ICompilationUnit referencedCU = projectScope.getCompilationUnitForScope(defs[0].getContainingScope());
-            getProject().addDependency(this, referencedCU, DependencyType.INHERITANCE, defs[0].getQualifiedName());
+            IDefinition[] baseDefs = projectScope.findAllDefinitionsByName(Multiname.crackDottedQName(getProject(), embedData.getTranscoder().getBaseClassQName()));
+            if(baseDefs == null || baseDefs.length == 0)
+            {
+                IDefinition[] subDefs = projectScope.findAllDefinitionsByName(Multiname.crackDottedQName(getProject(), embedData.getQName()));
+                ICompilerProblem problem = new UnknownSuperclassProblem(
+                    subDefs[0], embedData.getTranscoder().getBaseClassQName());
+                problems.add(problem);
+            }
+            else
+            {
+                ICompilationUnit referencedCU = projectScope.getCompilationUnitForScope(baseDefs[0].getContainingScope());
+                getProject().addDependency(this, referencedCU, DependencyType.INHERITANCE, baseDefs[0].getQualifiedName());
+            }
         }
     }