Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] java.lang.ClassCircularityError: sun/net/www/protocol/http/HttpURLConnection #48

Open
yupd opened this issue Oct 26, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@yupd
Copy link

yupd commented Oct 26, 2023

2023-10-26 12:24:09.791 WARNING localhost.localdomain [DEFAULT] [com.jrasp.agent.core.manager.RaspClassFileTransformer._transform] transform: sun/net/www/protocol/http/HttpURLConnection failed, in loader: null
java.lang.ClassCircularityError: sun/net/www/protocol/http/HttpURLConnection
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.jrasp.agent.core.enhance.EventEnhancer$1.getCommonSuperClass(EventEnhancer.java:50)
at org.objectweb.asm.SymbolTable.addMergedType(SymbolTable.java:1202)
at org.objectweb.asm.Frame.merge(Frame.java:1299)
at org.objectweb.asm.Frame.merge(Frame.java:1207)
at org.objectweb.asm.MethodWriter.computeAllFrames(MethodWriter.java:1611)
at org.objectweb.asm.MethodWriter.visitMaxs(MethodWriter.java:1547)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:2665)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1514)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:744)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:424)
at com.jrasp.agent.core.enhance.EventEnhancer.toByteCodeArray(EventEnhancer.java:80)
at com.jrasp.agent.core.manager.RaspClassFileTransformer._transform(RaspClassFileTransformer.java:74)
at com.jrasp.agent.core.manager.RaspClassFileTransformer.transform(RaspClassFileTransformer.java:52)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at sun.net.www.protocol.http.Handler.openConnection(Handler.java:62)
at sun.net.www.protocol.http.Handler.openConnection(Handler.java:57)
at java.net.URL.openConnection(URL.java:1002)
at net.sf.ehcache.util.UpdateChecker.getUpdateProperties(UpdateChecker.java:151)
at net.sf.ehcache.util.UpdateChecker.doCheck(UpdateChecker.java:117)
at net.sf.ehcache.util.UpdateChecker.checkForUpdate(UpdateChecker.java:104)
at net.sf.ehcache.util.UpdateChecker.run(UpdateChecker.java:95)

@xl1605368195 xl1605368195 added the bug Something isn't working label Oct 26, 2023
@liuqiang1008
Copy link

这个bug有解决方案吗

@xl1605368195
Copy link
Collaborator

这个问题正在解决。根因是类加载器问题。jrasp 重写了ClassWriter的getCommonSuperClass,获取类加载器的方法getClassLoader也要重写,使用上下文类加载器。
org/ow2/asm/asm/9.3/asm-9.3.jar!/org/objectweb/asm/ClassWriter.class 中有下面2个方法:

protected String getCommonSuperClass(final String type1, final String type2) {
  ClassLoader classLoader = getClassLoader();
  Class<?> class1;
  try {
    class1 = Class.forName(type1.replace('/', '.'), false, classLoader);
  } catch (ClassNotFoundException e) {
    throw new TypeNotPresentException(type1, e);
  }
  Class<?> class2;
  try {
    class2 = Class.forName(type2.replace('/', '.'), false, classLoader);
  } catch (ClassNotFoundException e) {
    throw new TypeNotPresentException(type2, e);
  }
  if (class1.isAssignableFrom(class2)) {
    return type1;
  }
  if (class2.isAssignableFrom(class1)) {
    return type2;
  }
  if (class1.isInterface() || class2.isInterface()) {
    return "java/lang/Object";
  } else {
    do {
      class1 = class1.getSuperclass();
    } while (!class1.isAssignableFrom(class2));
    return class1.getName().replace('.', '/');
  }
}

/**
 * Returns the {@link ClassLoader} to be used by the default implementation of {@link
 * #getCommonSuperClass(String, String)}, that of this {@link ClassWriter}'s runtime type by
 * default.
 *
 * @return ClassLoader
 */
protected ClassLoader getClassLoader() {
  return getClass().getClassLoader();
}

@liuqiang1008 @yupd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants