ObjectDB ObjectDB

Issue #2859: NullPointerException: Cannot invoke "com.objectdb.o.RFV.S()" because "<local9>" is null

Type: Bug ReoprtVersion: 2.8.9Priority: HighStatus: FixedReplies: 4
#1

Using @Index for fields and combine this with sorting the query throws an NullPointerException. This code reproduces the error:

public class NullTest {

    @Entity
    @Indices({
        @Index(members = {"children.name"}),
        @Index(members = {"children.age"})
    })
    static class Parent {
        String name;
        @Embedded
        List<Child> children;
    }

    @Embeddable
    static class Child {
        String name;
        Integer age;
    }

    public static void main(String[] args) {
        Child child = new Child();
        child.name = "Foo";
        child.age = 42;
        Parent parent = new Parent();
        parent.name = "Bar";
        parent.children = Collections.singletonList(child);

        EntityManagerFactory emf = Persistence.createEntityManagerFactory("foo.odb");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        em.persist(parent);
        em.getTransaction().commit();

        System.out.println(em.createQuery("select from Parent p join p.children c where c.age = 42 and c.name = 'Foo' order by name", Parent.class).getResultList().size());
    }
}

The Message thrown is:

com.objectdb.o.InternalException: java.lang.NullPointerException: Cannot invoke "com.objectdb.o.RFV.S()" because "<local9>" is null
java.lang.NullPointerException: Cannot invoke "com.objectdb.o.RFV.S()" because "<local9>" is null
    at com.objectdb.o.PLN.ZG(PLN.java:564)
    at com.objectdb.o.TAI.ZG(TAI.java:203)
    at com.objectdb.o.TAI.Zn(TAI.java:136)
    at com.objectdb.o.XQI.Zn(XQI.java:57)
    at com.objectdb.o.GQI.Zn(GQI.java:123)
    at com.objectdb.o.SQI.Zn(SQI.java:110)
    at com.objectdb.o.PRG.h(PRG.java:698)
    at com.objectdb.o.PRG.g(PRG.java:560)
    at com.objectdb.o.QRM.ZP(QRM.java:287)
    at com.objectdb.o.MST.ZP(MST.java:1026)
    at com.objectdb.o.WRA.ZP(WRA.java:313)
    at com.objectdb.o.WSM.ZP(WSM.java:117)
    at com.objectdb.o.QRR.k(QRR.java:260)
    at com.objectdb.o.QRR.i(QRR.java:154)
    at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:726)
    at org.example.NullTest.main(NullTest.java:43)
edit
delete
#2

We will check why this exception is thrown instead of an error message.

However, the query seems to be invalid, and should be:

select p from Parent p join p.children c
where c.age = 42 and c.name = 'Foo'
order by p.name

 

ObjectDB Support
edit
delete
#3

Checking this further, although using name rather than p.name is not standard JPA, it is acceptable by ObjectDB. The issue is related to your other report, and there is no exception/error when using the combined index or no index.

ObjectDB Support
edit
delete
#4

Thanks for the hint with the query. I used the correct query in the code above but the exceptions is still thrown. But only for the first time you run the code. If you run the code with existing foo.odb and second, third, ... entry was added, than it works.

edit
delete
#5

Solving issue #2858 seems to solve this issue as well.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.