Browse Source

Fix Bug 550290 - Lack of TypeSafeEnum#hashCode may lead to non-deterministic bytecode

tags/V1_9_5
Andy Clement 4 years ago
parent
commit
af640d2d88

+ 11
- 10
org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java View File

@@ -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);

+ 25
- 9
org.aspectj.matcher/src/main/java/org/aspectj/weaver/AdviceKind.java View File

@@ -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;
}
}

+ 18
- 18
org.aspectj.matcher/src/main/java/org/aspectj/weaver/Shadow.java View File

@@ -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()) {

+ 21
- 9
util/src/main/java/org/aspectj/util/TypeSafeEnum.java View File

@@ -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);
}
}

Loading…
Cancel
Save