spotify / missinglink

Build time tool for detecting link problems in java projects
Apache License 2.0
144 stars 27 forks source link

Fail to spot NoClassDefFound error for supertype #25

Closed pettermahlen closed 9 years ago

pettermahlen commented 9 years ago

I haven't got the exact example in front of me, but it was similar to:


   String something = SomeClass.class.toString();

   public class SomeClass implements InterfaceNotOnClassPath {}

The SomeClass.class.toString() invocation throws a NoClassDefFoundError because SomeClass fails to load since the interface is not on the class path.

pettermahlen commented 9 years ago

This seems to be a case of the following byte code being issued:

    LDC LSomeClass;.class
    INVOKEVIRTUAL java/lang/Class.getCanonicalName ()Ljava/lang/String;

LDC with a symbolic reference to a class causes that class to be resolved, and it's that resolution that's failing. We should possibly/probably add checks for that kind of class resolution.