java.lang.TypeNotPresentException when using reflection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I have been attempting to use reflection, in particular to get the superclass of a particular class, but this seems to fail when using Classpath v0.97.2 with JamVM 1.5.0.

In a stripped down version of what I am trying to achieve, I am attempting to run the following code, which I have unceremoniously poached from http://developer.classpath.org/pipermail/classpath/2006-November/001605.html :

public class Main {

    static class A extends ArrayList<String> {};

    public static void main(String[] args)
    {
        A a = new A();
        Object x = a;
        ((Collection)x).add(new Byte((byte) 1));
        System.out.println(x.getClass().getGenericSuperclass());
        System.out.println("We have a list parametrized with: " +
                ((ParameterizedType)x.getClass().getGenericSuperclass()).getActualTypeArguments()[0]);
    }
}

This code is compiled using the Eclipse Compiler and run on a PowerPC implementation. Classpath was compiled using Sun's javac compiler, version 1.6. Running the code, however, yields the following stack trace:

# jamvm -Xbootclasspath:/share/jamvm/classes:/usr/local/classpath/share/classpath Main
java.lang.TypeNotPresentException: type "java$util$ArrayList" not found
at gnu.java.lang.reflect.ParameterizedTypeImpl.resolve(GenericSignatureParser.java:127)
at gnu.java.lang.reflect.TypeImpl.resolve(TypeImpl.java:59)
at gnu.java.lang.reflect.ClassSignatureParser.getSuperclassType(ClassSignatureParser.java:83)
at java.lang.Class.getGenericSuperclass(Class.java:1712)
at Main.main(Main.java:16)
Caused by: java.lang.ClassNotFoundException: java$util$ArrayList
at java.lang.VMClass.forName(Native Method)
at java.lang.Class.forName(Class.java:233)
at gnu.java.lang.reflect.ParameterizedTypeImpl.resolve(GenericSignatureParser.java:123)
...4 more


It seems to me that the refelction doesn't seem to be finding the type correctly. Does anybody have any insight as to why this might be?

I have found the following older forum posts, but neither have been that helpful in trying to diagnose the issue.

http://developer.classpath.org/pipermail/classpath/2006-November/001605.html
http://www.nabble.com/Error-in-resolving-java.util.Set-td9779444.html

Thanks!

Tom


[Index of Archives]     [Linux Kernel]     [Linux Cryptography]     [Fedora]     [Fedora Directory]     [Red Hat Development]

  Powered by Linux