@Test public void testGetCommonSuperClass() { ClassWriter classWriter = new ClassWriter(0); assertEquals( "java/lang/Object", classWriter.getCommonSuperClass("java/lang/Object", "java/lang/Integer")); assertEquals( "java/lang/Object", classWriter.getCommonSuperClass("java/lang/Integer", "java/lang/Object")); assertEquals( "java/lang/Object", classWriter.getCommonSuperClass("java/lang/Integer", "java/lang/Runnable")); assertEquals( "java/lang/Object", classWriter.getCommonSuperClass("java/lang/Runnable", "java/lang/Integer")); assertEquals( "java/lang/Throwable", classWriter.getCommonSuperClass( "java/lang/IndexOutOfBoundsException", "java/lang/AssertionError")); Exception exception = assertThrows( TypeNotPresentException.class, () -> classWriter.getCommonSuperClass("-", "java/lang/Object")); assertEquals("Type - not present", exception.getMessage()); exception = assertThrows( TypeNotPresentException.class, () -> classWriter.getCommonSuperClass("java/lang/Object", "-")); assertEquals("Type - not present", exception.getMessage()); }
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('.', '/'); } }
ClassWriter extends ClassVisitor { 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('.', '/'); } } }
ClassWriter extends ClassVisitor { 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('.', '/'); } } ClassWriter(final int flags);  ClassWriter(final ClassReader classReader, final int flags); }
ClassWriter extends ClassVisitor { 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('.', '/'); } } ClassWriter(final int flags);  ClassWriter(final ClassReader classReader, final int flags); @Override final void visit(
      final int version,
      final int access,
      final String name,
      final String signature,
      final String superName,
      final String[] interfaces); @Override final void visitSource(final String file, final String debug); @Override final ModuleVisitor visitModule(
      final String name, final int access, final String version); @Override final void visitNestHost(final String nestHost); @Override final void visitOuterClass(
      final String owner, final String name, final String descriptor); @Override final AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible); @Override final AnnotationVisitor visitTypeAnnotation(
      final int typeRef, final TypePath typePath, final String descriptor, final boolean visible); @Override final void visitAttribute(final Attribute attribute); @Override final void visitNestMember(final String nestMember); @Override final void visitInnerClass(
      final String name, final String outerName, final String innerName, final int access); @Override final FieldVisitor visitField(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final Object value); @Override final MethodVisitor visitMethod(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final String[] exceptions); @Override final void visitEnd(); byte[] toByteArray(); int newConst(final Object value); int newUTF8(final String value); int newClass(final String value); int newMethodType(final String methodDescriptor); int newModule(final String moduleName); int newPackage(final String packageName); @Deprecated int newHandle(
      final int tag, final String owner, final String name, final String descriptor); int newHandle(
      final int tag,
      final String owner,
      final String name,
      final String descriptor,
      final boolean isInterface); int newConstantDynamic(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object... bootstrapMethodArguments); int newInvokeDynamic(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object... bootstrapMethodArguments); int newField(final String owner, final String name, final String descriptor); int newMethod(
      final String owner, final String name, final String descriptor, final boolean isInterface); int newNameType(final String name, final String descriptor); }
ClassWriter extends ClassVisitor { 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('.', '/'); } } ClassWriter(final int flags);  ClassWriter(final ClassReader classReader, final int flags); @Override final void visit(
      final int version,
      final int access,
      final String name,
      final String signature,
      final String superName,
      final String[] interfaces); @Override final void visitSource(final String file, final String debug); @Override final ModuleVisitor visitModule(
      final String name, final int access, final String version); @Override final void visitNestHost(final String nestHost); @Override final void visitOuterClass(
      final String owner, final String name, final String descriptor); @Override final AnnotationVisitor visitAnnotation(final String descriptor, final boolean visible); @Override final AnnotationVisitor visitTypeAnnotation(
      final int typeRef, final TypePath typePath, final String descriptor, final boolean visible); @Override final void visitAttribute(final Attribute attribute); @Override final void visitNestMember(final String nestMember); @Override final void visitInnerClass(
      final String name, final String outerName, final String innerName, final int access); @Override final FieldVisitor visitField(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final Object value); @Override final MethodVisitor visitMethod(
      final int access,
      final String name,
      final String descriptor,
      final String signature,
      final String[] exceptions); @Override final void visitEnd(); byte[] toByteArray(); int newConst(final Object value); int newUTF8(final String value); int newClass(final String value); int newMethodType(final String methodDescriptor); int newModule(final String moduleName); int newPackage(final String packageName); @Deprecated int newHandle(
      final int tag, final String owner, final String name, final String descriptor); int newHandle(
      final int tag,
      final String owner,
      final String name,
      final String descriptor,
      final boolean isInterface); int newConstantDynamic(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object... bootstrapMethodArguments); int newInvokeDynamic(
      final String name,
      final String descriptor,
      final Handle bootstrapMethodHandle,
      final Object... bootstrapMethodArguments); int newField(final String owner, final String name, final String descriptor); int newMethod(
      final String owner, final String name, final String descriptor, final boolean isInterface); int newNameType(final String name, final String descriptor); static final int COMPUTE_MAXS; static final int COMPUTE_FRAMES; }