ObjectDB ObjectDB

[ObjectDB 2.2.6_02] Unexpected exception (Error 990) at com.objectdb.o.OBC.aJ(OBC.java:961)

#1

I was experiencing an exception so I did a test to reproduce it.   here it is.

[ObjectDB 2.2.6_02] Unexpected exception (Error 990)

  Generated by Java HotSpot(TM) Client VM 1.6.0_17 (on Windows XP 5.1).
Please report this error on http://www.objectdb.com/database/issue/new
com.objectdb.o.InternalException: java.lang.NullPointerException: null
java.lang.NullPointerException
at com.objectdb.o.OBC.aJ(OBC.java:961)
at com.objectdb.o.OBC.aI(OBC.java:883)
at com.objectdb.o.EMR.n(EMR.java:146)
at com.objectdb.o.EMR.h(EMR.java:82)
at com.objectdb.o.TVS.Um(TVS.java:185)
at com.objectdb.o.UML.w(UML.java:547)
at com.objectdb.o.MMM.ad(MMM.java:975)
at com.objectdb.o.UTY.visitRefs(UTY.java:1143)
at com.objectdb.o.TVS.j(TVS.java:169)
at com.objectdb.o.TVS.cascade(TVS.java:156)
at com.objectdb.o.TVS.g(TVS.java:105)
at com.objectdb.o.TVS.g(TVS.java:93)
at com.objectdb.jpa.EMImpl.merge(EMImpl.java:450)
at com.reproduce.error.ReproduceTest.edit(ReproduceTest.java:116)

at com.reproduce.error.ReproduceTest.performTest(ReproduceTest.java:61)

at com.reproduce.error.ReproduceTest.main(ReproduceTest.java:28)

 

The code is as follows:

package com.reproduce.error;

 

import java.math.BigInteger;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityNotFoundException;
import javax.persistence.Persistence;
public class ReproduceTest {

 

    public static void main(String[] args) {
        // initialise
        ReproduceTest test = new ReproduceTest();
        TimePeriod tp = new TimePeriod();
        tp.setPeriodType("Test");
        tp.setBeginTime(new GregorianCalendar(1965, 06, 13));
        tp.setEndTime(new GregorianCalendar(2011, 06, 13));
        // perform the test
        try {
            test.performTest(BigInteger.ONE, BigInteger.TEN, tp);
        } catch (Exception ex) {
            Logger.getLogger(ReproduceTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    private EntityManagerFactory emf;
    public ReproduceTest() {
        emf = Persistence.createEntityManagerFactory("ReproducePU");
    }

 

    public EntityManager getEntityManager() {
        return emf.createEntityManager();
    }
    public void performTest(BigInteger x, BigInteger y, TimePeriod identifier)
            throws Exception {
        // obtain the moment
        Calendar now = Calendar.getInstance();
        MomentEntity moment = findMomentEntity(now.getTimeInMillis());
        if (moment == null) {
            create(new MomentEntity(now.getTimeInMillis()));
            moment = findMomentEntity(now.getTimeInMillis());
        }
        // create an instance of point on the chart
        PointEntity latestPoint = new PointEntity(moment);
        latestPoint.setX(x);
        latestPoint.setY(y);
        // create and update a Chart
        ChartEntity chart = new ChartEntity(identifier);
        create(chart);
        chart.addPoint(latestPoint);
        edit(chart);
    }

 

    public MomentEntity findMomentEntity(Long id) {
        EntityManager em = getEntityManager();
        try {
            return em.find(MomentEntity.class, id);
        } finally {
            em.close();
        }
    }
    public void create(MomentEntity moment) throws Exception {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            em.persist(moment);
            em.getTransaction().commit();
        } catch (Exception ex) {
            if (findMomentEntity(moment.getDateTime()) != null) {
                throw new EntityExistsException("MomentEntity " + moment + " already exists.", ex);
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

 

    public void create(ChartEntity chart) throws Exception  {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            em.persist(chart);
            em.getTransaction().commit();
        } catch (Exception ex) {
            if (findChart(chart.getId()) != null) {
                throw new EntityExistsException("ChartEntity " + chart + " already exists.", ex);
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }
    public void edit(ChartEntity chart) throws Exception  {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            chart = em.merge(chart);
            em.getTransaction().commit();
        } catch (Exception ex) {
            String msg = ex.getLocalizedMessage();
            if (msg == null || msg.length() == 0) {
                TimePeriod id = chart.getId();
                if (findChart(id) == null) {
                    throw new EntityNotFoundException("The ChartEntity with id " + id + " no longer exists.");
                }
            }
            throw  ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }

 

    public ChartEntity findChart(TimePeriod id) {
        EntityManager em = getEntityManager();
        try {
            return em.find(ChartEntity.class, id);
        } finally {
            em.close();
        }
    }
}

 

And now the Entity Classes:

See attached zip file

edit
delete
#2

Thank you for your report and for the test.

Please try build 2.2.6_03 that should fix this exception.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.