Commit b1cf816c2756ee207a8ad82ff739161de567e7fd

Authored by Mumfrey
1 parent 7a0a5ccd

Prevent ASM ClassWriter from swallowing important exceptions

src/main/java/com/mumfrey/liteloader/transformers/IsolatedClassWriter.java
... ... @@ -19,9 +19,57 @@ public class IsolatedClassWriter extends ClassWriter
19 19 {
20 20 super(flags);
21 21 }
22   -
  22 +
23 23 public IsolatedClassWriter(ClassReader classReader, int flags)
24 24 {
25 25 super(classReader, flags);
26 26 }
  27 +
  28 + /**
  29 + * Returns the common super type of the two given types. The default
  30 + * implementation of this method <i>loads</i> the two given classes and uses
  31 + * the java.lang.Class methods to find the common super class. It can be
  32 + * overridden to compute this common super type in other ways, in particular
  33 + * without actually loading any class, or to take into account the class
  34 + * that is currently being generated by this ClassWriter, which can of
  35 + * course not be loaded since it is under construction.
  36 + *
  37 + * @param type1 the internal name of a class.
  38 + * @param type2 the internal name of another class.
  39 + * @return the internal name of the common super class of the two given
  40 + * classes.
  41 + */
  42 + @Override
  43 + protected String getCommonSuperClass(final String type1, final String type2)
  44 + {
  45 + Class<?> c, d;
  46 + ClassLoader classLoader = getClass().getClassLoader();
  47 + try
  48 + {
  49 + c = Class.forName(type1.replace('/', '.'), false, classLoader);
  50 + d = Class.forName(type2.replace('/', '.'), false, classLoader);
  51 + }
  52 + catch (Exception e)
  53 + {
  54 + throw new RuntimeException(e.toString(), e);
  55 + }
  56 +
  57 + if (c.isAssignableFrom(d))
  58 + {
  59 + return type1;
  60 + }
  61 + if (d.isAssignableFrom(c))
  62 + {
  63 + return type2;
  64 + }
  65 + if (c.isInterface() || d.isInterface())
  66 + {
  67 + return "java/lang/Object";
  68 + }
  69 + do
  70 + {
  71 + c = c.getSuperclass();
  72 + } while (!c.isAssignableFrom(d));
  73 + return c.getName().replace('.', '/');
  74 + }
27 75 }
... ...