Home » Modeling » OCL » NullPointerException after EMF Code Generation with OCL Constraints
NullPointerException after EMF Code Generation with OCL Constraints [message #1149455] |
Tue, 22 October 2013 01:24  |
Eclipse User |
|
|
|
Hi,
I am using Kepler (4.3.0) and OCL 4.1.1.
I extended the well known library ecore example with some OCL constraints from the great tutorial in the Eclipse help.
Then I generated code from the ecore using the default settings.
Now I'd like to invoke a getter 'getLoans' for a derived feature on my Book object:
public static void main(String[] args)
{
Book book = LibFactory.eINSTANCE.createBook();
List<Loan> loans = book.getLoans();
}
Unfortunately I get the following NullPointerException:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$InternalSettingDelegateMany.dynamicGet(EStructuralFeatureImpl.java:1705)
at lib.impl.BookImpl.getLoans(BookImpl.java:466)
at ocl.library.test.OCLTest.main(OCLTest.java:14)
When I inspect the code, it seems that the code generation is somehow wrong, because the getter 'getLoans' in 'BookImpl' is implemented like this:
public EList<Loan> getLoans()
{
return (EList<Loan>)LOANS__ESETTING_DELEGATE.dynamicGet(this, null, 0, true, false);
}
The second parameter is null. If we look into the 'dynamicGet' method of 'InternalSettingDelegateMany', we see that in the first line it is assumed that the second parameter 'settings' is not null.
public Object dynamicGet(InternalEObject owner, EStructuralFeature.Internal.DynamicValueHolder settings, int index, boolean resolve, boolean coreType)
{
Object result = settings.dynamicGet(index);
if (result == null)
{
settings.dynamicSet(index, result = createDynamicSetting(owner));
}
if (!coreType)
{
switch (style)
{
case EMAP_UNSETTABLE:
case EMAP : return ((EMap<?, ?>)result).map();
case FEATURE_MAP : return ((FeatureMap.Internal)result).getWrapper();
}
}
return result;
}
Is this a bug? Or am I doing something wrong?
The project with library.ecore, library.genmodel, the generated code and the class OCLTest with the main method is included in the attached zip file.
|
|
|
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1149640 is a reply to message #1149455] |
Tue, 22 October 2013 03:50   |
Eclipse User |
|
|
|
Hi
This looks very like
https://bugs.eclipse.org/bugs/show_bug.cgi?id=418716#c3 but also looks
like functionality that must have been working...
I thought it might be a missing "readonly", but that didn't help.
It's looking suspiciously as if the EMF JET templates have improved...
Need to investigate.
Regards
Ed Willink
On 22/10/2013 06:24, Stephan Krusche wrote:
> Hi,
>
> I am using Kepler (4.3.0) and OCL 4.1.1.
> I extended the well known library ecore example with some OCL constraints from the great tutorial in the Eclipse help.
>
> Then I generated code from the ecore using the default settings.
> Now I'd like to invoke a getter 'getLoans' for a derived feature on my Book object:
>
>
> public static void main(String[] args)
> {
> Book book = LibFactory.eINSTANCE.createBook();
> List<Loan> loans = book.getLoans();
> }
>
>
> Unfortunately I get the following NullPointerException:
>
>
> Exception in thread "main" java.lang.NullPointerException
> at org.eclipse.emf.ecore.impl.EStructuralFeatureImpl$InternalSettingDelegateMany.dynamicGet(EStructuralFeatureImpl.java:1705)
> at lib.impl.BookImpl.getLoans(BookImpl.java:466)
> at ocl.library.test.OCLTest.main(OCLTest.java:14)
>
>
> When I inspect the code, it seems that the code generation is somehow wrong, because the getter 'getLoans' in 'BookImpl' is implemented like this:
>
>
> public EList<Loan> getLoans()
> {
> return (EList<Loan>)LOANS__ESETTING_DELEGATE.dynamicGet(this, null, 0, true, false);
> }
>
>
> The second parameter is null. If we look into the 'dynamicGet' method of 'InternalSettingDelegateMany', we see that in the first line it is assumed that the second parameter 'settings' is not null.
>
>
> public Object dynamicGet(InternalEObject owner, EStructuralFeature.Internal.DynamicValueHolder settings, int index, boolean resolve, boolean coreType)
> {
> Object result = settings.dynamicGet(index);
> if (result == null)
> {
> settings.dynamicSet(index, result = createDynamicSetting(owner));
> }
> if (!coreType)
> {
> switch (style)
> {
> case EMAP_UNSETTABLE:
> case EMAP : return ((EMap<?, ?>)result).map();
> case FEATURE_MAP : return ((FeatureMap.Internal)result).getWrapper();
> }
> }
> return result;
> }
>
>
> Is this a bug? Or am I doing something wrong?
>
> The project with library.ecore, library.genmodel, the generated code and the class OCLTest with the main method is included in the attached zip file.
|
|
| | | | | | | | | |
Goto Forum:
Current Time: Tue Jul 22 15:24:09 EDT 2025
Powered by FUDForum. Page generated in 0.05002 seconds
|