Skip to content

Commit

Permalink
fix: 修复问题 #455
Browse files Browse the repository at this point in the history
  • Loading branch information
dukun committed May 8, 2024
1 parent 3fad3a8 commit fc108cb
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,6 @@ private static Map<String, String> toFeatureMap(final String featureString) {

// KV对片段数组
final String[] kvPairSegmentArray = featureString.split(";");
if (kvPairSegmentArray.length == 0) {
return featureMap;
}

for (String kvPairSegmentString : kvPairSegmentArray) {
if (isBlankString(kvPairSegmentString)) {
Expand Down
11 changes: 9 additions & 2 deletions sandbox-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>once</forkMode>
<!-- <forkMode>once</forkMode> -->
<!-- set sun.zip.disableMemoryMapping property to avoid jvm crash when jar file modify in test case @link -> SpecialRoutingHandler#getRoutingYamlConfig -->
<!-- see jvm bug @ https://bugs.openjdk.org/browse/JDK-8190772 -->
<argLine>-Xbootclasspath/p:./src/test/resources/lib/sandbox-spy-1.3.0-for-qatest.jar -Dsun.zip.disableMemoryMapping=true</argLine>
Expand Down Expand Up @@ -150,7 +150,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.4</version>
<version>9.7</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
Expand All @@ -170,4 +170,11 @@
</dependency>

</dependencies>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.alibaba.jvm.sandbox.core;

import org.objectweb.asm.Opcodes;

/**
* 常量类
*/
public interface Constants {

/**
* 支持的ASM版本
*/
int SUPPORT_ASM = Opcodes.ASM9;

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alibaba.jvm.sandbox.core.enhance;

import com.alibaba.jvm.sandbox.api.event.Event;
import com.alibaba.jvm.sandbox.core.Constants;
import com.alibaba.jvm.sandbox.core.enhance.weaver.asm.EventWeaver;
import com.alibaba.jvm.sandbox.core.util.AsmUtils;
import com.alibaba.jvm.sandbox.core.util.ObjectIDs;
Expand All @@ -17,7 +18,6 @@
import static org.objectweb.asm.ClassReader.EXPAND_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_MAXS;
import static org.objectweb.asm.Opcodes.ASM7;

/**
* 事件代码增强器
Expand Down Expand Up @@ -104,7 +104,7 @@ public byte[] toByteCodeArray(final ClassLoader targetClassLoader,
final ClassWriter cw = createClassWriter(targetClassLoader, cr);
final int targetClassLoaderObjectID = ObjectIDs.instance.identity(targetClassLoader);
cr.accept(
new EventWeaver(ASM7, cw, namespace, listenerId,
new EventWeaver(Constants.SUPPORT_ASM, cw, namespace, listenerId,
targetClassLoaderObjectID,
cr.getClassName(),
signCodes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public DefaultCoreLoadedClassDataSource(final Instrumentation inst,
@Override
public Set<Class<?>> list() {
final Set<Class<?>> classes = new LinkedHashSet<>();
for(final Class<?> clazz : inst.getAllLoadedClasses()) {
classes.add(clazz);
}
Collections.addAll(classes, (Class<?>[])inst.getAllLoadedClasses());
return classes;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alibaba.jvm.sandbox.core.util.matcher.structure;

import com.alibaba.jvm.sandbox.api.util.LazyGet;
import com.alibaba.jvm.sandbox.core.Constants;
import com.alibaba.jvm.sandbox.core.util.BitUtils;
import com.alibaba.jvm.sandbox.core.util.collection.Pair;
import com.alibaba.jvm.sandbox.core.util.matcher.structure.PrimitiveClassStructure.Primitive;
Expand Down Expand Up @@ -256,14 +257,14 @@ public class ClassStructureImplByAsm extends FamilyClassStructure {
private Access fixAccess() {
final AtomicInteger accessRef = new AtomicInteger(this.classReader.getAccess());
final String internalClassName = this.classReader.getClassName();
this.classReader.accept(new ClassVisitor(ASM7) {
this.classReader.accept(new ClassVisitor(Constants.SUPPORT_ASM) {
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
if (StringUtils.equals(name, internalClassName)) {
accessRef.set(access);
}
}
}, ASM7);
}, Constants.SUPPORT_ASM);
return new AccessImplByAsm(accessRef.get());
}

Expand Down Expand Up @@ -413,7 +414,7 @@ public List<ClassStructure> getInterfaceClassStructures() {
@Override
protected List<ClassStructure> initialValue() {
final List<ClassStructure> annotationTypeClassStructures = new ArrayList<>();
accept(new ClassVisitor(ASM7) {
accept(new ClassVisitor(Constants.SUPPORT_ASM) {

@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
Expand Down Expand Up @@ -442,7 +443,7 @@ public List<ClassStructure> getAnnotationTypeClassStructures() {
@Override
protected List<BehaviorStructure> initialValue() {
final List<BehaviorStructure> behaviorStructures = new ArrayList<>();
accept(new ClassVisitor(ASM7) {
accept(new ClassVisitor(Constants.SUPPORT_ASM) {

@Override
public MethodVisitor visitMethod(final int access,
Expand All @@ -457,7 +458,7 @@ public MethodVisitor visitMethod(final int access,
return super.visitMethod(access, name, desc, signature, exceptions);
}

return new MethodVisitor(ASM7, super.visitMethod(access, name, desc, signature, exceptions)) {
return new MethodVisitor(Constants.SUPPORT_ASM, super.visitMethod(access, name, desc, signature, exceptions)) {

private final Type methodType = Type.getMethodType(desc);
private final List<ClassStructure> annotationTypeClassStructures = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alibaba.jvm.sandbox.qatest.core.enhance.transformer;

import com.alibaba.jvm.sandbox.core.Constants;
import com.alibaba.jvm.sandbox.core.enhance.weaver.asm.AsmMethods;
import com.alibaba.jvm.sandbox.core.enhance.weaver.asm.AsmTypes;
import com.alibaba.jvm.sandbox.core.util.AsmUtils;
Expand All @@ -15,7 +16,6 @@
import static org.objectweb.asm.ClassReader.EXPAND_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
import static org.objectweb.asm.ClassWriter.COMPUTE_MAXS;
import static org.objectweb.asm.Opcodes.ASM7;

/**
* 测试第三方增强冲突情况
Expand All @@ -35,7 +35,7 @@ public byte[] transform(ClassLoader loader, byte[] classfileBuffer){
// 返回增强后字节码
final ClassReader cr = new ClassReader(classfileBuffer);
final ClassWriter cw = createClassWriter(loader, cr);
cr.accept(new ThirdClassVisitor(ASM7,cw,signCodes,cr.getClassName()),
cr.accept(new ThirdClassVisitor(Constants.SUPPORT_ASM,cw,signCodes,cr.getClassName()),
EXPAND_FRAMES
);
return dumpClassIfNecessary(cr.getClassName(), cw.toByteArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ private static String buildSignCode(final String javaClassName,
buildSignCode(PACKAGE_PREFIX + "ChildClass", "methodOfChildClassWithAnnotation"),
new BehaviorStructureAsserter()
.assertExceptionTypes(buildJavaClassNameArrayAsserter(
"java.lang.IllegalStateException",
"java.lang.RuntimeException"
))
.assertAnnotationTypes(buildJavaClassNameArrayAsserter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void methodOfArrayArguments(


@InheritedAnnotation
public void methodOfChildClassWithAnnotation() throws IllegalStateException, RuntimeException {
public void methodOfChildClassWithAnnotation() throws RuntimeException {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ public void detail(final Map<String, String> param,
final int cCnt = moduleManager.cCnt(info.id());
final int mCnt = moduleManager.mCnt(info.id());
final File jarFile = moduleManager.getJarFile(info.id());
String sb = "" +
" ID : " + info.id() + "\n" +
String sb = " ID : " + info.id() + "\n" +
" VERSION : " + info.version() + "\n" +
" AUTHOR : " + info.author() + "\n" +
"JAR_FILE : " + jarFile.getPath() + "\n" +
Expand Down

0 comments on commit fc108cb

Please sign in to comment.