Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Stephan Krusche is currently offline 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 03:50 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
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 #1152044 is a reply to message #1149640] Wed, 23 October 2013 15:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
On 22/10/2013 08:50, Ed Willink wrote:
> It's looking suspiciously as if the EMF JET templates have improved...
> Need to investigate.
No. They've always been wrong.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=420208 raised.

Regards

Ed Willink
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1152099 is a reply to message #1152044] Wed, 23 October 2013 16:26 Go to previous messageGo to next message
Stephan Krusche is currently offline Stephan Krusche
Messages: 18
Registered: September 2012
Junior Member
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?
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1152125 is a reply to message #1152099] Wed, 23 October 2013 16:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
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?
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1152136 is a reply to message #1152125] Wed, 23 October 2013 16:55 Go to previous messageGo to next message
Christian W. Damus is currently offline Christian W. Damus
Messages: 761
Registered: July 2009
Senior Member
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?
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1152690 is a reply to message #1152125] Thu, 24 October 2013 01:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

I omitted the more obvious workaround.

Use direct OCL to Java code generation so that you don't use the
delegates at all.

See
http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.ocl.doc%2Fhelp%2FCodeGenerationTutorial.html

Regards

Ed Willink

On 23/10/2013 21:46, Ed Willink wrote:
> 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?
>
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1152731 is a reply to message #1152690] Thu, 24 October 2013 02:18 Go to previous messageGo to next message
Stephan Krusche is currently offline Stephan Krusche
Messages: 18
Registered: September 2012
Junior Member
Hi Ed,

actually we like to use direct code generation, but as described in http://www.eclipse.org/forums/index.php/mv/msg/465436/1149641/#msg_1149641 we get an exception for our quite complex model with more than 100 classes and 30 ocl constraints.
Unfortunately I am not allowed to post this complex model here, so I first need to reproduce the error with the library.ecore. (I did not have enough time for this until now)

Therefore I wanted to know whether it is possible to use the other way, i.e. using delegates. As I could reproduce the NPE when using delegates easily in the library.ecore, I hoped that we can find an acceptable workaround, but the suggested solutions do not fit Sad

Thanks
Stephan
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1152911 is a reply to message #1152731] Thu, 24 October 2013 04:46 Go to previous message
Ed Willink is currently offline Ed Willink
Messages: 4003
Registered: July 2009
Senior Member
Hi

You can post me a DropBox or equivalent link to your full model project
if that helps.

Regards

Ed

On 24/10/2013 07:18, Stephan Krusche wrote:
> Hi Ed,
>
> actually we like to use direct code generation, but as described in
> http://www.eclipse.org/forums/index.php/mv/msg/465436/1149641/#msg_1149641
> we get an exception for our quite complex model with more than 100
> classes and 30 ocl constraints.
> Unfortunately I am not allowed to post this complex model here, so I
> first need to reproduce the error with the library.ecore. (I did not
> have enough time for this until now)
>
> Therefore I wanted to know whether it is possible to use the other
> way, i.e. using delegates. As I could reproduce the NPE when using
> delegates easily in the library.ecore, I hoped that we can find an
> acceptable workaround, but the suggested solutions do not fit :(
>
> Thanks
> Stephan
Previous Topic:Debugging OCL constraints in UML profiles
Next Topic:Programmatically load a complete OCL file
Goto Forum:
  


Current Time: Wed Jul 23 22:35:35 EDT 2014

Powered by FUDForum. Page generated in 0.02013 seconds