Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » NPE due to null source
NPE due to null source [message #1804731] Sat, 30 March 2019 17:51 Go to next message
Alain Picard is currently offline Alain PicardFriend
Messages: 223
Registered: July 2009
Senior Member
I have an OCL that is failing with an NPE in EcoreEvaluationEnvironment#callOperation since the source argument is null. AFAIK null is only valid for static methods for method.invoke.

When tracing through the code, the issue is that a reference is not found in EvaluationVisitorImpl#visitOperationCallExp as shown in the attached image.

Question: Why isn't the sourceVal being tested for isUndefined when the body is null?

Thanks
Alain
Re: NPE due to null source [message #1804733 is a reply to message #1804731] Sat, 30 March 2019 18:06 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6438
Registered: July 2009
Senior Member
Hi

You don't provide nearly enough of a repro to go on. No stack trace. Not even an OCL version, which means I don't know whether it's fixed. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=483246#c3 The code seems familiar, so I think I did fix something , possibly a better diagnostic, but IIRC you only actually get down the problem path if you use an unregistered method.

Regards

Ed Willink
Re: NPE due to null source [message #1804734 is a reply to message #1804733] Sat, 30 March 2019 18:51 Go to previous messageGo to next message
Alain Picard is currently offline Alain PicardFriend
Messages: 223
Registered: July 2009
Senior Member
Ed,

Thanks for the quick reply.

First I checked the current code and nothing in any of the relevant part of the stack trace has changed, so I can pretty surely say that it is not fixed/changed, other than as you said reporting the method that failed to be invoked in the error message.

Right now I am using a pretty old version, 3.5.0_v20150521-1211

My OCL is: self.measuredCharacteristics->select(mc | mc.characteristicDefinition.getSingleMeasure().name = 'Business Capability Criticality').measurements->size()

and the failure point is that: mc.characteristicDefinition return null resulting in a call to getSingleMeasure() eOperation via method.invoke to fail.

I am not sure about the meaning of your statement "IIRC you only actually get down the problem path if you use an unregistered method".

Here is the relevant part of the stacktrace:
!ENTRY org.eclipse.ocl 4 10 2019-03-30 14:45:10.926
!MESSAGE ERROR in (calloperation): (null)
!STACK 0
java.lang.NullPointerException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.ocl.AbstractEvaluationEnvironment.callOperation(AbstractEvaluationEnvironment.java:198)
	at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.callOperation(EcoreEvaluationEnvironment.java:159)
	at org.eclipse.ocl.ecore.EcoreEvaluationEnvironment.callOperation(EcoreEvaluationEnvironment.java:1)
	at org.eclipse.ocl.EvaluationVisitorImpl.visitOperationCallExp(EvaluationVisitorImpl.java:271)
	at org.eclipse.ocl.ecore.impl.OperationCallExpImpl.accept(OperationCallExpImpl.java:384)
	at org.eclipse.ocl.EvaluationVisitorImpl.visitPropertyCallExp(EvaluationVisitorImpl.java:2298)
	at org.eclipse.ocl.ecore.impl.PropertyCallExpImpl.accept(PropertyCallExpImpl.java:232)
	at org.eclipse.ocl.AbstractEvaluationVisitor.safeVisitExpression(AbstractEvaluationVisitor.java:569)
	at org.eclipse.ocl.EvaluationVisitorImpl.visitOperationCallExp(EvaluationVisitorImpl.java:232)
	at org.eclipse.ocl.ecore.impl.OperationCallExpImpl.accept(OperationCallExpImpl.java:384)
	at org.eclipse.ocl.AbstractEvaluationVisitor.visitExpression(AbstractEvaluationVisitor.java:242)
	at org.eclipse.ocl.internal.evaluation.IterationTemplate.evaluate(IterationTemplate.java:81)
	at org.eclipse.ocl.EvaluationVisitorImpl.evaluateSelectIterator(EvaluationVisitorImpl.java:2013)
	at org.eclipse.ocl.EvaluationVisitorImpl.visitIteratorExp(EvaluationVisitorImpl.java:1814)
	at org.eclipse.ocl.ecore.impl.IteratorExpImpl.accept(IteratorExpImpl.java:108)
	at org.eclipse.ocl.EvaluationVisitorImpl.visitIteratorExp(EvaluationVisitorImpl.java:1798)
	at org.eclipse.ocl.ecore.impl.IteratorExpImpl.accept(IteratorExpImpl.java:108)
	at org.eclipse.ocl.AbstractEvaluationVisitor.safeVisitExpression(AbstractEvaluationVisitor.java:569)
	at org.eclipse.ocl.EvaluationVisitorImpl.visitOperationCallExp(EvaluationVisitorImpl.java:232)
	at org.eclipse.ocl.ecore.impl.OperationCallExpImpl.accept(OperationCallExpImpl.java:384)
	at org.eclipse.ocl.AbstractEvaluationVisitor.visitExpression(AbstractEvaluationVisitor.java:242)
	at org.eclipse.ocl.internal.evaluation.QueryImpl.evaluate(QueryImpl.java:123)
	at org.eclipse.ocl.ecore.QueryImpl.evaluate(QueryImpl.java:64)
	at com.castortech.iris.models.query.ocl.BaseOclQueryHandler.run(BaseOclQueryHandler.java:89)

Re: NPE due to null source [message #1804741 is a reply to message #1804734] Sat, 30 March 2019 21:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6438
Registered: July 2009
Senior Member
Hi

Well that seems precisely in line with the Bug 483246 fix. Navigating from null is invalid. If you use the latest code you will get a clean invalid rather than a dirty NPE and consequential invalid.

If you use a more recent OCL editor you can enable null safe validation so that such hazards are avoided.

Regards

Ed Willink
Re: NPE due to null source [message #1804756 is a reply to message #1804741] Sun, 31 March 2019 15:10 Go to previous messageGo to next message
Alain Picard is currently offline Alain PicardFriend
Messages: 223
Registered: July 2009
Senior Member
Ed,

Thanks so much. I updated to the latest release and got the changes.

I would just recommend changing the message binding since when logged it still shows up as an error due to binding with OCLMessages.ErrorMessage_ERROR_, instead of a version that would provide a WARNING log entry message.

Thanks
Alain
Re: NPE due to null source [message #1804758 is a reply to message #1804756] Sun, 31 March 2019 17:16 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6438
Registered: July 2009
Senior Member
Hi

Your use case seems slightly different to the bug. It would be really helpful to have the repro / screen shots so that I can understnad haow poor the ergonomics is.

Regards

Ed Willink
Re: NPE due to null source [message #1804760 is a reply to message #1804758] Sun, 31 March 2019 17:27 Go to previous messageGo to next message
Alain Picard is currently offline Alain PicardFriend
Messages: 223
Registered: July 2009
Senior Member
Ed,

Here are 2 screenshots, First is the query from our UI and 2nd is the result with the breakpoint. I highlighted the problematic part.

In this case, as mentioned yesterday, "mc.characteristicDefinition" can return null in some cases, which leads to the exception.

Regards,
Alain
Re: NPE due to null source [message #1804772 is a reply to message #1804760] Mon, 01 April 2019 05:48 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6438
Registered: July 2009
Senior Member
Hi

You really don't give me anything to go on.

I don't know what tool you are using. I don't know how you execute the OCL. I don't know how the error arises, except it appears to be a custom caller which strongly suggests that the custom caller is badly coded.

All I see is bad OCL gives bad result. Correct. Poor custom error handling gives user dissatisfaction. Pity, but that's not an OCL problem.

Regards

Ed Willink
Previous Topic:Announce OCL 6.7.0
Next Topic:Tuple type availability in Acceleo OCL
Goto Forum:
  


Current Time: Tue Aug 20 16:22:06 GMT 2019

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

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

Back to the top