Issue #672: com.objectdb.o.InternalException: java.lang.ArrayIndexOutOfBoundsException: null:

Type: Bug ReoprtVersion: 2.3.6Priority: CriticalStatus: FixedReplies: 3
#1

The following error appears under and extended persistence context, and with creation, configuration and wiring code that is known to work perfectly with EclipseLink+Glassfish:

SEVERE: Unexpected internal exception

SEVERE: [ObjectDB 2.3.6_16] Unexpected exception (Error 990)
  Generated by Java HotSpot(TM) 64-Bit Server VM 1.6.0_26 (on Mac OS X 10.5.8).
Please report this error on http://www.objectdb.com/database/issue/new
com.objectdb.o.InternalException: java.lang.ArrayIndexOutOfBoundsException: null
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.objectdb.o.PAG.u(PAG.java:254)
at com.objectdb.o.SSS.R(SSS.java:349)
at com.objectdb.o.SSS.Q(SSS.java:331)
at com.objectdb.o.SFL.ad(SFL.java:831)
at com.objectdb.o.MST.ad(MST.java:1339)
at com.objectdb.o.MST.Va(MST.java:1230)
at com.objectdb.o.WRA.Va(WRA.java:355)
at com.objectdb.o.WSM.Va(WSM.java:146)
at com.objectdb.o.STC.u(STC.java:494)
at com.objectdb.o.SHN.am(SHN.java:544)
at com.objectdb.o.SHN.K(SHN.java:167)
at com.objectdb.o.HND.run(HND.java:133)
at java.lang.Thread.run(Thread.java:655)

..

WARNING: A system exception occurred during an invocation on EJB ExtGreenStarRequestBean method public com.greensoft.entity.Element com.greensoft.greenstar.ejb.ext.ExtGreenStarRequestBean.createGreenStarElementByClassWithInit(java.lang.Class,com.greensoft.entity.Element,com.greensoft.greenstar.entity.office.GreenStarOfficeProject,java.lang.String,com.greensoft.entity.Source)
javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean
at com.sun.ejb.containers.BaseContainer.checkExceptionClientTx(BaseContainer.java:5049)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4884)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at $Proxy244.createGreenStarElementByClassWithInit(Unknown Source)
at com.greensoft.greenstar.ejb.ext.__EJB31_Generated__ExtGreenStarRequestBean__Intf____Bean__.createGreenStarElementByClassWithInit(Unknown Source)
at com.greensoft.greenstar.ejb.ext.ExtGreenStarOfficeProjectBuilder.constraint_To_be_eligible_for_Green_Star_assessment_Class_5_Commercial_Office_GFA_must_account_for_at_least_80percent_of_the_total_GFA(ExtGreenStarOfficeProjectBuilder.java:298)
at com.greensoft.greenstar.ejb.ext.ExtGreenStarOfficeProjectBuilder.buildProject(ExtGreenStarOfficeProjectBuilder.java:217)
at com.greensoft.greenstar.ejb.ext.ExtGreenStarOfficeProjectBuilder.buildProjectProfiled(ExtGreenStarOfficeProjectBuilder.java:172)

..

Caused by: javax.ejb.EJBException: Unexpected internal exception
at com.greensoft.greenstar.ejb.ext.ExtGreenStarRequestBean.createGreenStarElementByClassWithInit(ExtGreenStarRequestBean.java:73)

..
@Stateless
@LocalBean
public class ExtGreenStarRequestBean extends ExtRequestCommon {

..

public <T extends Element> T createGreenStarElementByClassWithInit(
            Class<T> clazz,
            Element owner,
            GreenStarOfficeProject project,
            String name,
            Source source
            ) {
        try {
            Constructor constructor = clazz.getConstructor(Element.class, GreenStarOfficeProject.class, String.class);
            //version that can pass Project to kids in init()
            T t = (T)constructor.newInstance(owner,project,name);
            t.setSource(source);
            initElement(t,owner);
            return t;
        } catch (InstantiationException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (IllegalArgumentException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (SecurityException ex) {
            logger.log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            throw new EJBException(ex.getMessage());
        }
        return null;
    }

where:

    abstract public class ExtRequestCommon extends All_ {

and it is triggered from:

@Stateful
@LocalBean
public class ExtGreenStarOfficeProjectBuilder extends ResettableBuilder {

    @PersistenceContext(type = PersistenceContextType.EXTENDED)//!
    protected EntityManager em;

    @EJB
    public//! so not reset() and so builders can access
            ExtRequestBean request;

    @EJB
    public//! so not reset() and so builders can access
            ExtGreenStarRequestBean greenStarRequest;

..

private Constraint constraint_To_be_eligible_for_Green_Star_assessment_Class_5_Commercial_Office_GFA_must_account_for_at_least_80percent_of_the_total_GFA;
protected Constraint constraint_To_be_eligible_for_Green_Star_assessment_Class_5_Commercial_Office_GFA_must_account_for_at_least_80percent_of_the_total_GFA(){
if (constraint_To_be_eligible_for_Green_Star_assessment_Class_5_Commercial_Office_GFA_must_account_for_at_least_80percent_of_the_total_GFA == null) {
  constraint_To_be_eligible_for_Green_Star_assessment_Class_5_Commercial_Office_GFA_must_account_for_at_least_80percent_of_the_total_GFA =
          //request.createConstraint(
          greenStarRequest.createGreenStarElementByClassWithInit(
          Constraint_Class5CommercialOfficeGFAPercentage.class,
          null,
          project(),
          "To be eligible for Green Star assessment, Class 5 Commercial Office GFA must account for at least 80% of the total GFA",
          source());

I am not getting any part of the trace that reveals what inside com.greensoft.greenstar.ejb.ext.ExtGreenStarRequestBean.createGreenStarElementByClassWithInit is causing problems, but here are the culprits:

/**
     * Persists the element, with logging, and updates the owner.
     *
     * @param element
     * @param owner
     */
    protected void initElement(Element element, Element owner) {
        persistElement(element);
        updateOwner(owner, element);
        //return true;
    }

/**
     * Wraps central {@link #persist} method in logging diagnostics for an {@link Element}.
     */
    protected void persistElement(Element e) {
        log_created(e);
        persist(e);
        log_persisted(e);
    }


protected void persist(Object o) {
        if (DO_CHECK_REPEAT_PERSIST && isPersisted(o)) {
            log_warn("persist", "SKIPPING: Object already persisted:" + o);
        } else {
            try {
                em.persist(o);
                if (Global.USE_OBJECTDB) {
                    em.flush(); //ObjectDB ensure id exists.
                }
                if (DO_CHECK_REPEAT_PERSIST) {
                    persisted.add(o);
                }
            } catch (Exception ex) {
                log_error(ex);
                //throw new EJBException("RequestCommon: persist FAILS", ex);
                throw new EJBException(ex.getMessage());
            }
        }
    }

protected boolean updateOwner(Element owner, Element ownedElement) {
        if (DO_PRE_FLUSH) {
            em.flush();
        }
        if (owner == null) {
            return false; //TODO? throw IllegalArgumentException: NO, sometimes want null owner. ?WARN
        }
        if (ownedElement == null) {
            throw new IllegalArgumentException("null ownedElement");
        }
        if (ownedElement.getOwner() != owner) {
            String $error = "given owner(" + owner + ") does not match constructed owner(" + ownedElement.getOwner() + ") of ownedElement(" + ownedElement + ")";
            log_error("updateOwner", $error);
            throw new IllegalArgumentException($error);
        }
        boolean ok = owner.addOwnedElement(ownedElement);
//        if (ok) {
//            em.merge(owner);
//        }
        return ok;
    }

 

#2

The stack trace indicates an unexpected state of ObjectDB but doesn't provide much details on the cause of this unexpected state (except that this may be related to using large number of entity classes and/or sequences).

Can you post a test that causes this exception (here or in a support ticket)?

In this case isolating the problem may not be required since the problem is in the server, so just running your test web application against ObjectDB Server in the debugger could reveals the cause.

ObjectDB Support
#3

A workaround was found thanks to support using 16K page size in the database section of the config file:

<size initial="256kb" resize="256kb" page="16kb" />

#4

This was a critical bug that could corrupt databases when the total number of entity classes, indexes, and sequences is large. The workaround just increased the threshold but didn't fix the problem in the general case.

Build 2.3.7_01 fixes this issue. Thank you very much for your report.

ObjectDB Support

Reply