jOOQ / jOOR

jOOR - Fluent Reflection in Java jOOR is a very simple fluent API that gives access to your Java Class structures in a more intuitive way. The JDK's reflection APIs are hard and verbose to use. Other languages have much simpler constructs to access type meta information at runtime. Let us make Java reflection better.
http://www.jooq.org/products
Apache License 2.0
2.81k stars 376 forks source link

Reflect#type on instance fails for null field #37

Closed PascalSchumacher closed 7 years ago

PascalSchumacher commented 7 years ago

When using joor 0.9.6, this test:

public static class A {
    String f;
}

@Test
public void test() {
    A a = new A();
    for (Map.Entry<String, Reflect> field : Reflect.on(a).fields().entrySet()) {
        Reflect reflect = field.getValue();
        if (reflect.type() == String.class) {
            System.out.println("Value: " + reflect.get());
        }
    }
}

fails with:

java.lang.NullPointerException
    at org.joor.Reflect.type(Reflect.java:766)

By the way: Thank you very much for providing jOOR! :+1:

PascalSchumacher commented 7 years ago

No sure this is a bug. Maybe it would be solved by https://github.com/jOOQ/jOOR/issues/33?

lukaseder commented 7 years ago

Hmm, interesting. Thanks for reporting. I can definitely reproduce this. There's an entire set of use-cases that isn't currently covered and might produce this NPE. This isn't a duplicate of #33, but I definitely think that the Reflect instance should keep a reference of the instance and type of object for these cases.

Will need to think about this