1410 words

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

BugVersion: Priority: NormalStatus: FixedReplies: 1
#1
2011-06-08 00:45

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

longpat
longpat's picture
Joined on 2011-05-30
User Post #6
#2
2011-06-08 17:49

Thank you for your report and for the test.

Please try build 2.2.6_03 that should fix this exception.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #343

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel