Skip to main content


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 05:24 Go to next message
Stephan Krusche is currently offline Stephan KruscheFriend
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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
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 #1152044 is a reply to message #1149640] Wed, 23 October 2013 19:41 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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 20:26 Go to previous messageGo to next message
Stephan Krusche is currently offline Stephan KruscheFriend
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 20:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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 20:55 Go to previous messageGo to next message
Christian Damus is currently offline Christian DamusFriend
Messages: 1270
Registered: July 2009
Location: Canada
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 05:42 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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 06:18 Go to previous messageGo to next message
Stephan Krusche is currently offline Stephan KruscheFriend
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 08:46 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
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
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1738984 is a reply to message #1152911] Tue, 26 July 2016 14:21 Go to previous messageGo to next message
Klementina Josifovska is currently offline Klementina JosifovskaFriend
Messages: 8
Registered: December 2015
Junior Member
Hi,

how this problem has been solved so far?

Regards,
Re: NullPointerException after EMF Code Generation with OCL Constraints [message #1738987 is a reply to message #1738984] Tue, 26 July 2016 14:45 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It is not generally helpful to pick up such an old thread.

The original problem raised as
https://bugs.eclipse.org/bugs/show_bug.cgi?id=420208 was resolved as
INVALID. Not a problem. Just bad user initualization.

The follow on problem had no repro. Two years on quite a few OCL CG
fixes have been made so whatever the problem was might have been fixed.

If you have a CG problem please raise a Bugzilla.

Regards

Ed Willink




On 26/07/2016 15:21, Klementina Josifovska wrote:
> Hi,
> how this problem has been solved so far?
>
> Regards,


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Previous Topic:Announce OCL 6.2.0 release
Next Topic:Quick fix for OCLinEcore
Goto Forum:
  


Current Time: Tue Mar 19 03:40:15 GMT 2024

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

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

Back to the top