Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » NPE in GenModelImpl.getImportedName(String)
NPE in GenModelImpl.getImportedName(String) [message #482352] Wed, 26 August 2009 10:50 Go to next message
Eclipse UserFriend
Originally posted by: ben.tenne.gmail.com

I've hit a problem whereby model generation is failing due to a
NullPointerException in GenModelImpl.getImportedName(String).
Specifically, it's attempting to create a validator class and dealing with
an integer feature that will have java.math.BigInteger as its
implementation. I have a constraint that limits the total digits to 10,
so it's constructing a literal value of '10000000000' (i.e. max value + 1)
to validate against. In doing this, it attempts to make a call the the
GenModelImpl's ImportManager to deal with the 'java.math.BigInteger' name,
but it seems that the ImportManager is null at this point, so the call
fails with a NPE.

Without the total digits constraint, everything's fine.

I've tried to simplify my case as much as possible, giving the following
ecore file ('package1.ecore'):

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="package1"
nsURI="test1" nsPrefix="myprefix">
<eClassifiers xsi:type="ecore:EDataType" name="IntegerType"
instanceClassName="java.math.BigInteger">
<eAnnotations
source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="integer_._type"/>
<details key="baseType"
value="http://www.eclipse.org/emf/2003/XMLType#integer"/>
<details key="totalDigits" value="10"/>
</eAnnotations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="WeatherSummary">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="integer"
lowerBound="1" eType="//IntegerType" defaultValueLiteral="0"
unsettable="true">
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>

And here is the associated genmodel file ('package1.genmodel'):

<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
modelDirectory="/.package1/src" modelPluginID="package1"
modelName="package1" complianceLevel="5.0" copyrightFields="false">
<genPackages prefix="Package1" resource="XML"
disposableProviderFactory="true">
<ecorePackage href="package1.ecore#/"/>
<genDataTypes>
<ecoreDataType href="package1.ecore#//IntegerType"/>
</genDataTypes>
<genClasses>
<ecoreClass href="package1.ecore#//WeatherSummary"/>
<genFeatures createChild="false">
<ecoreFeature xsi:type="ecore:EAttribute"
href="package1.ecore#//WeatherSummary/integer"/>
</genFeatures>
</genClasses>
</genPackages>
</genmodel:GenModel>

Eclipse's GenModel editor claims this is valid when I right-click ->
validate.

Finally, here's the stack at the point where the call is attempted on the
null ImportManager:

Thread [ModalContext] (Suspended (exception NullPointerException))
GenModelImpl.getImportedName(String) line: 2029
Literals.importName(String, GenModel) line: 299
Literals.toBigIntegerLiteral(BigInteger, GenModel) line: 376
Literals.toLiteral(Object, boolean, GenModel) line: 136
GenDataTypeImpl.getStaticValue(String, boolean) line: 1159
GenDataTypeImpl.getStaticValue(String) line: 1123
GenDataTypeImpl.validTotalDigits(EDataType, int) line: 719
GenDataTypeImpl.getGenConstraints() line: 953
GenPackageImpl.hasConstraints() line: 2078
GenPackageGeneratorAdapter.generateValidatorClass(GenPackage , Monitor)
line: 480
GenPackageGeneratorAdapter.generateModel(Object, Monitor) line: 211
GenPackageGeneratorAdapter(GenBaseGeneratorAdapter).doGenera te(Object,
Object, Monitor) line: 220
GenPackageGeneratorAdapter(AbstractGeneratorAdapter).generat e(Object,
Object, Monitor) line: 290
Generator.generate(Object, Object, String, Monitor) line: 617
GenModelActionBarContributor$GenerateAction$1.execute(IProgr essMonitor)
line: 372
WorkspaceModifyOperation$1.run(IProgressMonitor) line: 104
Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor)
line: 1800
GenModelActionBarContributor$GenerateAction$1(WorkspaceModif yOperation).run(IProgressMonitor)
line: 116
ModalContext$ModalContextThread.run() line: 121

Interesting, I've noticed that if I add a second attribute to my class,
just a simple String, then everything completes properly. I'm in the
process of stepping through the code trying to work out why this makes a
difference.

I'd be very interested to hear if someone can throw some light on this.

Regards,
Ben.
Re: NPE in GenModelImpl.getImportedName(String) [message #482369 is a reply to message #482352] Wed, 26 August 2009 11:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070106060605040102090604
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Ben,

Please open a bugzilla. I think the Literals code needs to be tolerate
of there not being an import manager (as in this case where it's just
determining if there are valid constraints that will need to be generated):

### Eclipse Workspace Patch 1.0
#P org.eclipse.emf.codegen.ecore
Index: src/org/eclipse/emf/codegen/ecore/genmodel/impl/Literals.jav a
============================================================ =======
RCS file:
/cvsroot/modeling/org.eclipse.emf/org.eclipse.emf/plugins/or g.eclipse.emf.codegen.ecore/src/org/eclipse/emf/codegen/ecor e/genmodel/impl/Literals.java,v
retrieving revision 1.11
diff -u -r1.11 Literals.java
--- src/org/eclipse/emf/codegen/ecore/genmodel/impl/Literals.jav a
30 Apr 2009 14:54:08 -0000 1.11
+++ src/org/eclipse/emf/codegen/ecore/genmodel/impl/Literals.jav a
26 Aug 2009 11:21:31 -0000
@@ -296,7 +296,7 @@

private static String importName(String name, GenModel genModel)
{
- return genModel != null ? genModel.getImportedName(name) : name;
+ return genModel != null *&& genModel.getImportManager() !=
null* ? genModel.getImportedName(name) : name;
}

/**




Ben Tenne wrote:
> I've hit a problem whereby model generation is failing due to a
> NullPointerException in GenModelImpl.getImportedName(String).
> Specifically, it's attempting to create a validator class and dealing
> with an integer feature that will have java.math.BigInteger as its
> implementation. I have a constraint that limits the total digits to
> 10, so it's constructing a literal value of '10000000000' (i.e. max
> value + 1) to validate against. In doing this, it attempts to make a
> call the the GenModelImpl's ImportManager to deal with the
> 'java.math.BigInteger' name, but it seems that the ImportManager is
> null at this point, so the call fails with a NPE.
>
> Without the total digits constraint, everything's fine.
> I've tried to simplify my case as much as possible, giving the
> following ecore file ('package1.ecore'):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="package1"
> nsURI="test1" nsPrefix="myprefix">
> <eClassifiers xsi:type="ecore:EDataType" name="IntegerType"
> instanceClassName="java.math.BigInteger">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="integer_._type"/>
> <details key="baseType"
> value="http://www.eclipse.org/emf/2003/XMLType#integer"/>
> <details key="totalDigits" value="10"/>
> </eAnnotations>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="WeatherSummary">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="integer"
> lowerBound="1" eType="//IntegerType" defaultValueLiteral="0"
> unsettable="true">
> </eStructuralFeatures>
> </eClassifiers>
> </ecore:EPackage>
>
> And here is the associated genmodel file ('package1.genmodel'):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <genmodel:GenModel xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
> modelDirectory="/.package1/src" modelPluginID="package1"
> modelName="package1" complianceLevel="5.0" copyrightFields="false">
> <genPackages prefix="Package1" resource="XML"
> disposableProviderFactory="true">
> <ecorePackage href="package1.ecore#/"/>
> <genDataTypes>
> <ecoreDataType href="package1.ecore#//IntegerType"/>
> </genDataTypes>
> <genClasses>
> <ecoreClass href="package1.ecore#//WeatherSummary"/>
> <genFeatures createChild="false">
> <ecoreFeature xsi:type="ecore:EAttribute"
> href="package1.ecore#//WeatherSummary/integer"/>
> </genFeatures>
> </genClasses>
> </genPackages>
> </genmodel:GenModel>
>
> Eclipse's GenModel editor claims this is valid when I right-click ->
> validate.
>
> Finally, here's the stack at the point where the call is attempted on
> the null ImportManager:
>
> Thread [ModalContext] (Suspended (exception NullPointerException))
> GenModelImpl.getImportedName(String) line: 2029
> Literals.importName(String, GenModel) line: 299
> Literals.toBigIntegerLiteral(BigInteger, GenModel) line: 376
> Literals.toLiteral(Object, boolean, GenModel) line: 136
> GenDataTypeImpl.getStaticValue(String, boolean) line: 1159
> GenDataTypeImpl.getStaticValue(String) line: 1123
> GenDataTypeImpl.validTotalDigits(EDataType, int) line: 719
> GenDataTypeImpl.getGenConstraints() line: 953
> GenPackageImpl.hasConstraints() line: 2078
> GenPackageGeneratorAdapter.generateValidatorClass(GenPackage ,
> Monitor) line: 480
> GenPackageGeneratorAdapter.generateModel(Object, Monitor) line:
> 211
> GenPackageGeneratorAdapter(GenBaseGeneratorAdapter).doGenera te(Object,
> Object, Monitor) line: 220
> GenPackageGeneratorAdapter(AbstractGeneratorAdapter).generat e(Object,
> Object, Monitor) line: 290
> Generator.generate(Object, Object, String, Monitor) line: 617
> GenModelActionBarContributor$GenerateAction$1.execute(IProgr essMonitor)
> line: 372
> WorkspaceModifyOperation$1.run(IProgressMonitor) line: 104
> Workspace.run(IWorkspaceRunnable, ISchedulingRule, int,
> IProgressMonitor) line: 1800
> GenModelActionBarContributor$GenerateAction$1(WorkspaceModif yOperation).run(IProgressMonitor)
> line: 116
> ModalContext$ModalContextThread.run() line: 121
>
> Interesting, I've noticed that if I add a second attribute to my
> class, just a simple String, then everything completes properly. I'm
> in the process of stepping through the code trying to work out why
> this makes a difference.
>
> I'd be very interested to hear if someone can throw some light on this.
>
> Regards,
> Ben.
>

--------------070106060605040102090604
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Ben,<br>
<br>
Please open a bugzilla.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: NPE in GenModelImpl.getImportedName(String) [message #482393 is a reply to message #482369] Wed, 26 August 2009 12:37 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ben.tenne.gmail.com

Thanks Ed. I'll raise it.

Looking at the code in GenPackageImpl.hasConstraints(), I see that I can
work around this bug by engineering my package such that a classifier with
constraints appears before the one that's exposing the bug (given that the
method stops looking once it's found something).

Incidentally, with different test data, I hit the same problem in a
different context, as shown in the stacktrace below. Can you suggest
something I could do to my ecore/genmodel to avoid these problems?
Inclusion of a dummy class in each package isn't necessarily out of the
question, but something that has less obvious effect on the output would
be better.

Thread [ModalContext] (Suspended (exception NullPointerException))
GenModelImpl.getImportedName(String) line: 2029
Literals.importName(String, GenModel) line: 299
Literals.toBigIntegerLiteral(BigInteger, GenModel) line: 376
Literals.toLiteral(Object, boolean, GenModel) line: 136
GenDataTypeImpl.getStaticValue(String, boolean) line: 1159
GenDataTypeImpl.getStaticValue(String) line: 1123
GenDataTypeImpl.validTotalDigits(EDataType, int) line: 719
GenDataTypeImpl.getGenConstraints() line: 953
GenPackageImpl.hasConstraints() line: 2078
GenPackageImpl$ValidatorHelper.init() line: 2665
GenPackageImpl$ValidatorHelper.<init>(GenPackageImpl) line: 2637
GenPackageImpl.prepareCache() line: 3064
GenPackageGeneratorAdapter.doPreGenerate(Object, Object) line: 176
GenPackageGeneratorAdapter(AbstractGeneratorAdapter).preGene rate(Object,
Object) line: 256
Generator.generate(Object, Object, String, Monitor) line: 609
Generator.generate(Object, Object, Monitor) line: 528
[snip]

Regards,
Ben.
Re: NPE in GenModelImpl.getImportedName(String) [message #482402 is a reply to message #482393] Wed, 26 August 2009 12:59 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Ben,

An EDataType not based on BigDecimal with constraints earlier in the
package is the only workaround that comes to mind...


Ben Tenne wrote:
> Thanks Ed. I'll raise it.
>
> Looking at the code in GenPackageImpl.hasConstraints(), I see that I
> can work around this bug by engineering my package such that a
> classifier with constraints appears before the one that's exposing the
> bug (given that the method stops looking once it's found something).
>
> Incidentally, with different test data, I hit the same problem in a
> different context, as shown in the stacktrace below. Can you suggest
> something I could do to my ecore/genmodel to avoid these problems?
> Inclusion of a dummy class in each package isn't necessarily out of
> the question, but something that has less obvious effect on the output
> would be better.
>
> Thread [ModalContext] (Suspended (exception NullPointerException))
> GenModelImpl.getImportedName(String) line: 2029
> Literals.importName(String, GenModel) line: 299
> Literals.toBigIntegerLiteral(BigInteger, GenModel) line: 376
> Literals.toLiteral(Object, boolean, GenModel) line: 136
> GenDataTypeImpl.getStaticValue(String, boolean) line: 1159
> GenDataTypeImpl.getStaticValue(String) line: 1123
> GenDataTypeImpl.validTotalDigits(EDataType, int) line: 719
> GenDataTypeImpl.getGenConstraints() line: 953
> GenPackageImpl.hasConstraints() line: 2078
> GenPackageImpl$ValidatorHelper.init() line: 2665
> GenPackageImpl$ValidatorHelper.<init>(GenPackageImpl) line: 2637
> GenPackageImpl.prepareCache() line: 3064
> GenPackageGeneratorAdapter.doPreGenerate(Object, Object) line: 176
> GenPackageGeneratorAdapter(AbstractGeneratorAdapter).preGene rate(Object,
> Object) line: 256
> Generator.generate(Object, Object, String, Monitor) line: 609
> Generator.generate(Object, Object, Monitor) line: 528
> [snip]
>
> Regards,
> Ben.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Some informations
Next Topic:the right ResourceFactory for the right resource
Goto Forum:
  


Current Time: Tue Apr 23 09:10:43 GMT 2024

Powered by FUDForum. Page generated in 0.03780 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top