Fast Object Database for Java - with JPA/JDO support

Issue #2407: NullPointerException on TreeSet load

Type: Bug reoprtVersion: 2.7.6_01Priority: NormalStatus: FixedReplies: 2

I am getting a NullPointerException on an attempt to retrieve an object with a TreeSet:

SEVERE: Servlet.service() for servlet [web.TimelinesServlet] in context with path [/Timelines] threw exception
    at model.TimelineEntry.compareTo(
    at java.util.TreeMap.put(
    at java.util.TreeSet.add(
    at Source)
    at java.util.AbstractCollection.addAll(
    at java.util.TreeSet.addAll(
    at Source)
    at com.objectdb.o.CLT.r(
    at com.objectdb.o.TYT.extractCollection(
    at com.objectdb.o.ENT.extractCollection(
    at Source)
    at Source)
    at model.Timeline.jsonifyItems(
    at web.TimelinesServlet.sendTimelineData(
    at web.TimelinesServlet.doGet(
    at javax.servlet.http.HttpServlet.service(
    at javax.servlet.http.HttpServlet.service(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke(
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(
    at org.apache.catalina.core.StandardEngineValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.apache.coyote.http11.Http11Processor.service(
    at org.apache.coyote.AbstractProcessorLight.process(
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.util.concurrent.ThreadPoolExecutor$
    at org.apache.tomcat.util.threads.TaskThread$

The following test case demonstrates using a TreeSet and no exception is thrown:

import java.util.*;

import javax.persistence.*;

public class F2407 {
    public static void main(String[] args) {

        EntityManagerFactory emf;
        emf = Persistence.createEntityManagerFactory("objectdb:./db.tmp;drop");
        EntityManager em = emf.createEntityManager();
        MyEntity entity = new MyEntity();

        MyElement element1 = new MyElement();
        element1.s = "a"; 

        MyElement element2 = new MyElement();
        element2.s = "b"; 
        entity = em.find(MyEntity.class, 1);


    public static class MyEntity {
        Set<MyElement> set = new TreeSet();
    public static class MyElement implements Comparable {
        String s;
        public int compareTo(Object o) {
            return s.compareTo(((MyElement)o).s);
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

The test case in #2 above does throw an exception when the L2 cache is disabled, as the tree set elements are loaded lazily and not ready for comparison when the tree is built. Build 2.7.6_02 should fix the issue.

A possible workaround, if you use a previous version of ObjectDB, is to set fetch type to EAGER:

    public static class MyEntity {
        @OneToMany(cascade=CascadeType.PERSIST, fetch = FetchType.EAGER)
        Set<MyElement> set = new TreeSet();

Thank you for this report.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply