diff options
author | Andy Clement <aclement@pivotal.io> | 2019-09-09 16:58:48 -0700 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2019-09-09 16:58:48 -0700 |
commit | af640d2d8809a76f87519e09b5db1f3ce9a251f7 (patch) | |
tree | 752010f63b8c95bae1aa43402fa5d209ea9b0ab4 | |
parent | 589e3dc730d57c4d9c63fa79db97653a8e30c898 (diff) | |
download | aspectj-af640d2d8809a76f87519e09b5db1f3ce9a251f7.tar.gz aspectj-af640d2d8809a76f87519e09b5db1f3ce9a251f7.zip |
Fix Bug 550290 - Lack of TypeSafeEnum#hashCode may lead to non-deterministic bytecode
4 files changed, 75 insertions, 46 deletions
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java index e5201a3e9..31a1549ee 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java @@ -1,12 +1,12 @@ /* ******************************************************************* * Copyright (c) 2002-2010 Contributors - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: * PARC, Andy Clement (SpringSource) * ******************************************************************/ package org.aspectj.ajdt.internal.compiler.ast; @@ -15,6 +15,7 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -71,7 +72,7 @@ import org.aspectj.weaver.patterns.TypePattern; /** * Represents an aspect declaration. - * + * * @author PARC * @author Andy Clement */ @@ -83,7 +84,7 @@ public class AspectDeclaration extends TypeDeclaration { public ResolvedMember aspectOfMethod; public ResolvedMember ptwGetWithinTypeNameMethod; public ResolvedMember hasAspectMethod; - public Map<ResolvedMember, Binding> accessForInline = new HashMap<ResolvedMember, Binding>(); + public Map<ResolvedMember, Binding> accessForInline = new LinkedHashMap<ResolvedMember, Binding>(); public Map<ResolvedMember, AccessForInlineVisitor.SuperAccessMethodPair> superAccessForInline = new HashMap<ResolvedMember, AccessForInlineVisitor.SuperAccessMethodPair>(); public boolean isPrivileged; public EclipseSourceType concreteName; @@ -213,7 +214,7 @@ public class AspectDeclaration extends TypeDeclaration { } if ((binding.tagBits & TagBits.AnnotationResolved) != 0) { // possibly resolution occurred during hasUnsatisfiedDependency()... - binding.tagBits = (binding.tagBits & ~TagBits.AnnotationResolved); + binding.tagBits = (binding.tagBits & ~TagBits.AnnotationResolved); } Annotation atAspectAnnotation = AtAspectJAnnotationFactory.createAspectAnnotation(perClause.toDeclarationString(), declarationSourceStart); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/AdviceKind.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/AdviceKind.java index af0646935..3d5300110 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/AdviceKind.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/AdviceKind.java @@ -1,13 +1,13 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * PARC initial implementation * ******************************************************************/ package org.aspectj.weaver; @@ -18,7 +18,7 @@ import org.aspectj.util.TypeSafeEnum; /** * The five kinds of advice in AspectJ. - * + * * @author Erik Hilsdale * @author Jim Hugunin */ @@ -132,4 +132,20 @@ public class AdviceKind extends TypeSafeEnum { return this == PerThisEntry || this == PerTargetEntry; } + @Override + public int hashCode() { + return ((super.hashCode()*37 + precedence)*37+(isAfter?0:1))*37 + (isCflow?0:1); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof AdviceKind)) { + return false; + } + AdviceKind ak = (AdviceKind)o; + return super.equals(ak) && + ak.precedence == precedence && + ak.isAfter == isAfter && + ak.isCflow == isCflow; + } } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Shadow.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Shadow.java index 1a8ed5290..cde7e5163 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Shadow.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Shadow.java @@ -1,13 +1,13 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * PARC initial implementation + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * PARC initial implementation * ******************************************************************/ package org.aspectj.weaver; @@ -47,7 +47,7 @@ public abstract class Shadow { protected final Shadow enclosingShadow; protected List<ShadowMunger> mungers = Collections.emptyList(); protected boolean needAroundClosureStacking = false; - + public int shadowId = nextShadowID++; // every time we build a shadow, it gets a new id // ---- @@ -82,7 +82,7 @@ public abstract class Shadow { /** * the type of the this object here - * + * * @throws IllegalStateException if there is no this here */ public final UnresolvedType getThisType() { @@ -98,7 +98,7 @@ public abstract class Shadow { /** * a var referencing this - * + * * @throws IllegalStateException if there is no target here */ public abstract Var getThisVar(); @@ -118,7 +118,7 @@ public abstract class Shadow { /** * the type of the target object here - * + * * @throws IllegalStateException if there is no target here */ public final UnresolvedType getTargetType() { @@ -130,7 +130,7 @@ public abstract class Shadow { /** * a var referencing the target - * + * * @throws IllegalStateException if there is no target here */ public abstract Var getTargetVar(); @@ -266,7 +266,7 @@ public abstract class Shadow { /** * returns the resolved signature of the thing under this shadow - * + * */ public ResolvedMember getResolvedSignature() { if (resolvedSignature == null) { @@ -399,7 +399,7 @@ public abstract class Shadow { /** * These shadow kinds have return values that can be bound in after returning(Dooberry doo) advice. - * + * * @return */ public boolean hasReturnValue() { @@ -481,7 +481,7 @@ public abstract class Shadow { /** * Only does the check if the munger requires it (@AJ aspects don't) - * + * * @param munger * @return */ @@ -628,11 +628,11 @@ public abstract class Shadow { /** Actually implement the (non-empty) mungers associated with this shadow */ private void implementMungers() { - World world = getIWorld(); + World world = getIWorld(); needAroundClosureStacking = false; int annotationStyleWithAroundAndProceedCount = 0; for (ShadowMunger munger: mungers) { - if (munger.getDeclaringType()!= null && + if (munger.getDeclaringType()!= null && munger.getDeclaringType().isAnnotationStyleAspect() && munger.isAroundAdvice() && munger.bindsProceedingJoinPoint()) { diff --git a/util/src/main/java/org/aspectj/util/TypeSafeEnum.java b/util/src/main/java/org/aspectj/util/TypeSafeEnum.java index 99d223143..aba78b117 100644 --- a/util/src/main/java/org/aspectj/util/TypeSafeEnum.java +++ b/util/src/main/java/org/aspectj/util/TypeSafeEnum.java @@ -1,18 +1,19 @@ /* ******************************************************************* * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC). - * All rights reserved. - * This program and the accompanying materials are made available - * under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Xerox/PARC initial implementation + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Xerox/PARC initial implementation * ******************************************************************/ package org.aspectj.util; -import java.io.*; +import java.io.DataOutputStream; +import java.io.IOException; public class TypeSafeEnum { private byte key; @@ -41,4 +42,15 @@ public class TypeSafeEnum { public void write(DataOutputStream s) throws IOException { s.writeByte(key); } + @Override + public int hashCode() { + return name.hashCode()*37+key; + } + + @Override + public boolean equals(Object o) { + return (o instanceof TypeSafeEnum) && + ((TypeSafeEnum)o).key == key && + ((TypeSafeEnum)o).name.equals(name); + } } |