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 05:24 |
Stephan Krusche Messages: 18 Registered: September 2012 |
Junior Member |
|
|
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 07:50 |
Ed Willink Messages: 7655 Registered: July 2009 |
Senior Member |
|
|
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.
|
|
| | | |
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1152136 is a reply to message #1152125] |
Wed, 23 October 2013 20:55 |
|
Hi, Ed,
I doubt that I will have anything in M3. I have other contributions in
UML2, CDO, and Papyrus on the go that are ahead of bug 405065 on my
to-do list.
cW
On 2013-10-23 20:46:49 +0000, Ed Willink said:
> Hi
>
> Christian Damus is actively working on OCL for UML properties and is
> very likely to have to fix this problem on the way.
>
> The solution may be available for M3. Since it involves multiple
> projects, it might just miss the M3 deadline.
>
> ?? 'workaround's
> - avoid multiple multiplicity at the Java API, multiple multiplicity is
> ok if called from OCL
> - use dynamic rather than generated models
>
> Regards
>
> Ed
>
> On 23/10/2013 21:26, Stephan Krusche wrote:
>> Thanks for the response.
>> Any ideas for a workaround?
>> Or is it possible that you provide a bugfix for the next release? e.g. Luna M3?
|
|
| | | | | |
Goto Forum:
Current Time: Thu Apr 18 11:02:53 GMT 2024
Powered by FUDForum. Page generated in 0.03567 seconds
|