diff options
author | mikaelpeltier <mikaelpeltier@google.com> | 2015-06-03 17:26:58 +0200 |
---|---|---|
committer | mikaelpeltier <mikaelpeltier@google.com> | 2015-06-05 11:15:18 +0200 |
commit | 680315b2356968f93fc04e64e7f2f5c782f96357 (patch) | |
tree | b319e52b3aa8e20f7685ab721041deeb63cdf452 | |
parent | 921976d63c203e129f74b022a1fc13cddb5f8a3d (diff) | |
download | toolchain_jack-680315b2356968f93fc04e64e7f2f5c782f96357.zip toolchain_jack-680315b2356968f93fc04e64e7f2f5c782f96357.tar.gz toolchain_jack-680315b2356968f93fc04e64e7f2f5c782f96357.tar.bz2 |
JPackage should never try to load a renamed or deleted items
Bug: 21105000
Change-Id: I4f4b2d355e57deb9e00b64c0f263a75daf8505d0
(cherry picked from commit 69d2257dd865f3ba9012ad33dbceba97e15730b9)
3 files changed, 53 insertions, 10 deletions
diff --git a/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java b/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java index 60d91ce..e7857e6 100644 --- a/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java +++ b/jack/src/com/android/jack/ir/ast/JDefinedClassOrInterface.java @@ -573,6 +573,11 @@ public abstract class JDefinedClassOrInterface extends JDefinedReferenceType if (parent == null || parent != enclosingPackage) { throw new JNodeInternalError(this, "Invalid parent or enclosing package"); } + } + @Override + public void setName(@Nonnull String name) { + enclosingPackage.removeItemWithName(this); + super.setName(name); } } diff --git a/jack/src/com/android/jack/ir/ast/JPackage.java b/jack/src/com/android/jack/ir/ast/JPackage.java index 4f4bc9b..9b181d0 100644 --- a/jack/src/com/android/jack/ir/ast/JPackage.java +++ b/jack/src/com/android/jack/ir/ast/JPackage.java @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Set; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; @@ -92,6 +93,9 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi new ArrayList<JPhantomAnnotationType>(); @Nonnull + private final Set<String> deletedItems = new HashSet<String>(); + + @Nonnull private String name; @Nonnull @@ -127,10 +131,12 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi } public void addType(@Nonnull JDefinedClassOrInterface type) { + addItemWithName(type); declaredTypes.add(type); } public void addPackage(@Nonnull JPackage newPackage) { + addItemWithName(newPackage); subPackages.add(newPackage); } @@ -330,6 +336,9 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi @Override public void setName(@Nonnull String name) { + if (enclosingPackage != null) { + enclosingPackage.removeItemWithName(this); + } this.name = StringInterner.get().intern(name); } @@ -344,6 +353,8 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi @Override public void traverse(@Nonnull JVisitor visitor) { + assert enclosingPackage == null || !enclosingPackage.deletedItems.contains(getName()); + if (visitor.visit(this)) { if (visitor.needLoading()) { loadSubPackages(); @@ -395,6 +406,11 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi if (!found) { super.transform(existingNode, newNode, transformation); + } else { + if (transformation == Transformation.REMOVE) { + assert existingNode instanceof HasName; + removeItemWithName((HasName) existingNode); + } } } @@ -439,6 +455,8 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi @Nonnull protected JPackage loadSubPackage(@Nonnull String simpleName) throws JPackageLookupException { + assert !deletedItems.contains(simpleName); + List<PackageLoader> subLoaders = null; for (PackageLoader loader : loaders) { try { @@ -468,11 +486,13 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi } for (String name : subNames) { - try { - getSubPackage(name); - } catch (JPackageLookupException e) { - // We know the packages exist so this should not happen - throw new AssertionError(e); + if (!deletedItems.contains(name)) { + try { + getSubPackage(name); + } catch (JPackageLookupException e) { + // We know the packages exist so this should not happen + throw new AssertionError(e); + } } } } @@ -480,6 +500,7 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi @Nonnull protected JDefinedClassOrInterface loadClassOrInterface( @Nonnull String simpleName) throws JTypeLookupException { + assert !deletedItems.contains(simpleName); for (PackageLoader loader : loaders) { try { return loader.loadClassOrInterface(this, simpleName); @@ -497,11 +518,13 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi } for (String name : subNames) { - try { - getType(name); - } catch (JTypeLookupException e) { - // We know the packages exist so this should not happen - throw new AssertionError(e); + if (!deletedItems.contains(name)) { + try { + getType(name); + } catch (JTypeLookupException e) { + // We know the packages exist so this should not happen + throw new AssertionError(e); + } } } } @@ -520,4 +543,13 @@ public class JPackage extends JNode implements HasName, CanBeRenamed, HasEnclosi throw new JNodeInternalError(this, "Invalid parent or enclosing package"); } } + + void removeItemWithName(@Nonnull HasName itemWithName) { + deletedItems.add(itemWithName.getName()); + } + + private void addItemWithName(@Nonnull HasName itemWithName) { + assert itemWithName instanceof JPackage || itemWithName instanceof JClassOrInterface; + deletedItems.remove(itemWithName.getName()); + } } diff --git a/jack/src/com/android/jack/ir/ast/JPhantomClassOrInterface.java b/jack/src/com/android/jack/ir/ast/JPhantomClassOrInterface.java index 67950ad..a69c80a 100644 --- a/jack/src/com/android/jack/ir/ast/JPhantomClassOrInterface.java +++ b/jack/src/com/android/jack/ir/ast/JPhantomClassOrInterface.java @@ -162,4 +162,10 @@ public class JPhantomClassOrInterface extends JReferenceTypeCommon implements JC throw new JNodeInternalError(this, "Invalid parent"); } } + + @Override + public void setName(@Nonnull String name) { + enclosingPackage.removeItemWithName(this); + super.setName(name); + } } |