eclipse-ocl / org.eclipse.ocl

Eclipse Public License 2.0
0 stars 0 forks source link

org.eclipse.ocl.examples.codegen.oclinecore.OCLinEcoreTables: NPE during static initialization #1171

Closed eclipse-ocl-bot closed 2 weeks ago

eclipse-ocl-bot commented 2 weeks ago

| --- | --- | | Bugzilla Link | 415381 | | Status | CLOSED FIXED | | Importance | P3 normal | | Reported | Aug 19, 2013 16:12 EDT | | Modified | May 25, 2015 17:20 EDT | | Version | 4.0.0 | | Reporter | Nicolas Rouquette |

Description

Created attachment 234549\ ecore metamodel

I generated the java code for an ecore metamodel of OMG SysML/ValueTypes/QUDV with OCL constraints using Ed W.'s new XText-based OCL tooling:

https://hudson.eclipse.org/hudson/job/buckminster-ocl-branch-tests/381/artifact/MDT-OCL.downloads/mdt-ocl-Update-tools-201308160535.zip

The difference between the edw/414040 branch vs. HEAD is that in the edw/414040, there is a fix for generating scoped package names in case there are multiple EClasses of the same name in different EPackages of the genmodel's ecore metamodel. This is the case for the ecore/genmodel I produced for OMG's SysML 1.4 SysML/ValueTypes/QUDV (see attached).

The generated code includes a file:

/sysml_valuetype_qudv.metamodel/src-gen/SysML_ValueTypes_QUDV/UnitAndQuantityKind/UnitAndQuantityKindTables.java

(see attached).

The problem happens during the java static initialization when this class is loaded:

{code}

Caused by: java.lang.ExceptionInInitializerError\ at SysML_ValueTypes_QUDV.UnitAndQuantityKind.UnitAndQuantityKindTables$Types.(UnitAndQuantityKindTables.java:70)\ at SysML_ValueTypes_QUDV.QUDV.QUDVTables$Fragments.(QUDVTables.java:180)\ at SysML_ValueTypes_QUDV.QUDV.QUDVTables$TypeFragments.(QUDVTables.java:433)\ at SysML_ValueTypes_QUDV.QUDV.QUDVTables$Types.(QUDVTables.java:165)\ at SysML_ValueTypes_QUDV.QUDV.QUDVTables.(QUDVTables.java:1465)\ at SysML_ValueTypes_QUDV.QUDV.impl.DerivedQuantityKindImpl.dependsOnQuantityKinds(DerivedQuantityKindImpl.java:115)\ at SysML_ValueTypes_QUDV.QUDV.impl.QuantityKindImpl.getDependsOnQuantityKinds(QuantityKindImpl.java:147)\ at SysML_ValueTypes_QUDV.QUDV.impl.QuantityKindImpl.eIsSet(QuantityKindImpl.java:330)\ at SysML_ValueTypes_QUDV.QUDV.impl.DerivedQuantityKindImpl.eIsSet(DerivedQuantityKindImpl.java:231)\ at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eIsSet(BasicEObjectImpl.java:1237)\ at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:401)\ at org.eclipse.emf.ecore.util.EcoreUtil.resolveCrossReferences(EcoreUtil.java:303)\ at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.java:297)\ at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.java:282)\ at org.eclipse.emf.ecore.util.EcoreUtil.resolveAll(EcoreUtil.java:270)\ at org.eclipse.emf.editor.EEditor.findMetaModelPackages(EEditor.java:321)\ at org.eclipse.emf.editor.EEditor.createExtXptFacade(EEditor.java:304)\ at org.eclipse.emf.editor.EEditor.initInternal(EEditor.java:250)\ at org.eclipse.emf.editor.EEditor.createPages(EEditor.java:228)\ at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:358)\ at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:142)\ at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96)\ at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:323)\ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\ at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)\ at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\ at java.lang.reflect.Method.invoke(Method.java:597)\ at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56) ... 80 more\ Caused by: java.lang.NullPointerException\ at SysML_ValueTypes_QUDV.UnitAndQuantityKind.UnitAndQuantityKindTables.(UnitAndQuantityKindTables.java:274) ... 108 more\ {code}

The NPE happened with the generated code at the end of the file (line 274):

{code}\ /**\


import SysML_ValueTypes_QUDV.SysML_ValueTypes_QUDVPackage;\ import SysML_ValueTypes_QUDV.UnitAndQuantityKind.UnitAndQuantityKindPackage;\ import SysML_ValueTypes_QUDV.UnitAndQuantityKind.UnitAndQuantityKindTables;\ import org.eclipse.jdt.annotation.NonNull;\ import org.eclipse.ocl.examples.domain.ids.ClassId;\ import org.eclipse.ocl.examples.domain.ids.CollectionTypeId;\ import org.eclipse.ocl.examples.domain.ids.IdManager;\ import org.eclipse.ocl.examples.domain.ids.NsURIPackageId;\ import org.eclipse.ocl.examples.domain.ids.TypeId;\ import org.eclipse.ocl.examples.library.ecore.EcoreExecutorPackage;\ import org.eclipse.ocl.examples.library.ecore.EcoreExecutorProperty;\ import org.eclipse.ocl.examples.library.ecore.EcoreExecutorType;\ import org.eclipse.ocl.examples.library.ecore.EcoreLibraryOppositeProperty;\ import org.eclipse.ocl.examples.library.executor.ExecutorFragment;\ import org.eclipse.ocl.examples.library.executor.ExecutorOperation;\ import org.eclipse.ocl.examples.library.executor.ExecutorProperty;\ import org.eclipse.ocl.examples.library.executor.ExecutorPropertyWithImplementation;\ import org.eclipse.ocl.examples.library.executor.ExecutorStandardLibrary;\ import org.eclipse.ocl.examples.library.oclstdlib.OCLstdlibTables;

/**

Since this metamodel is broken into multiple EPackages that map to multiple Java packages, the code generator needs to enforce the static initialization of dependencies before using them to statically construct the values of static, final attributes.

Here's a manually modified version that works for me (look for the NFR) comments.

{code}

/**\


import SysML_ValueTypes_QUDV.SysML_ValueTypes_QUDVPackage;\ import SysML_ValueTypes_QUDV.UnitAndQuantityKind.UnitAndQuantityKindPackage;\ import SysML_ValueTypes_QUDV.UnitAndQuantityKind.UnitAndQuantityKindTables;\ import org.eclipse.jdt.annotation.NonNull;\ import org.eclipse.ocl.examples.domain.ids.ClassId;\ import org.eclipse.ocl.examples.domain.ids.CollectionTypeId;\ import org.eclipse.ocl.examples.domain.ids.IdManager;\ import org.eclipse.ocl.examples.domain.ids.NsURIPackageId;\ import org.eclipse.ocl.examples.domain.ids.TypeId;\ import org.eclipse.ocl.examples.library.ecore.EcoreExecutorPackage;\ import org.eclipse.ocl.examples.library.ecore.EcoreExecutorProperty;\ import org.eclipse.ocl.examples.library.ecore.EcoreExecutorType;\ import org.eclipse.ocl.examples.library.ecore.EcoreLibraryOppositeProperty;\ import org.eclipse.ocl.examples.library.executor.ExecutorFragment;\ import org.eclipse.ocl.examples.library.executor.ExecutorOperation;\ import org.eclipse.ocl.examples.library.executor.ExecutorProperty;\ import org.eclipse.ocl.examples.library.executor.ExecutorPropertyWithImplementation;\ import org.eclipse.ocl.examples.library.executor.ExecutorStandardLibrary;\ import org.eclipse.ocl.examples.library.oclstdlib.OCLstdlibTables;

/**

SysML_ValueTypes_QUDV.ecore

eclipse-ocl-bot commented 2 weeks ago

By Nicolas Rouquette on Aug 19, 2013 16:12

Created attachment 234550 genmodel

SysML_ValueTypes_QUDV.genmodel

eclipse-ocl-bot commented 2 weeks ago

By Ed Willink on Sep 04, 2013 09:00

Bug 414244 has been marked as a duplicate of this bug.

eclipse-ocl-bot commented 2 weeks ago

By Ed Willink on Sep 04, 2013 14:18

Thanks. A real bonus to geta good solution to a tricky problem as well.

Pushed to master for M2.

eclipse-ocl-bot commented 2 weeks ago

By Ed Willink on Jan 31, 2014 06:10

Bug 427103 has been marked as a duplicate of this bug.

eclipse-ocl-bot commented 2 weeks ago

By Ed Willink on May 25, 2015 17:20

CLOSED after more than a year in the RESOLVED state.