Home » Modeling » OCL » Null pointer exception problem with OCL parsing
Null pointer exception problem with OCL parsing [message #804311] |
Wed, 22 February 2012 13:10 |
Piotr J. Puczynski Messages: 17 Registered: January 2012 |
Junior Member |
|
|
Hi.
I am using org.eclipse.ocl_3.1.0.v20110913-1213 and org.eclipse.ocl.uml_3.1.0.v20110913-1213.
I have a problem with OCL parsing during the JUnit tests. It seems to work when the Topcased IDE is lunched but it fails during the JUnit tests (as stand alone).
I have two test cases ; one parses Boolean value "true" and other parses "Set { 1 , 2 , 5 , 88 }".
The first does not trigger an error, second does. The context of the expressions is InstanceSpecification.
I initialize ocl :
System.setProperty("org.eclipse.ocl.uml", repositoryPath + "libs/ocl");
System.setProperty("org.eclipse.uml2.uml.resources", repositoryPath + "libs/uml");
String result = org.eclipse.ocl.uml.OCL.initialize(null); // null for global init
assert result == null;
The initialized system properties directories contain extracted plugins and the returned string is always null. I use null as a parameter but I also tried with resourceSet and usage of resurceSet in fact does not help.
My code of evaluation is:
UMLEnvironmentFactory envFactory = new UMLEnvironmentFactory(constraint.getModel().eResource().getResourceSet());
UMLEnvironment env = envFactory.createEnvironment();
org.eclipse.ocl.uml.OCL myOCL = org.eclipse.ocl.uml.OCL.newInstance(env);
EvaluationEnvironment<?, ?, ?, ?, ?> evalEnv = myOCL.getEvaluationEnvironment();
EvaluationOptions.setOption(evalEnv, UMLEvaluationOptions.EVALUATION_MODE, EvaluationMode.RUNTIME_OBJECTS);
OCLExpression<?> oclConstraint = null;
myOCL.setEvaluationTracingEnabled(true);
myOCL.setParseTracingEnabled(true);
OCLHelper<?, ?, ?, ?> helper = myOCL.createOCLHelper();
helper.setInstanceContext(executor.getInstanceSpecification());
String body = calculateBody();
try {
oclConstraint = helper.createQuery(body); //here the error appears
} catch (ParserException e) {
executor.getChecker().addOtherProblem(Diagnostic.ERROR, "OCL parsing exception of '" + body + "': " + e.getMessage(), constraint.getOwner());
return false;
}
@SuppressWarnings("unchecked")
Object result = myOCL.evaluate(executor.getInstanceSpecification(), (OCLExpression<Classifier>) oclConstraint);
I know this type of errors can be caused by wrong initialization but I am doing initialization... so my ideas finished. I traced an error in the OCL parser code and it seem to be thrown in line
C resultType = getSetType(env, oclFactory, getTupleType(env,
oclFactory, createTupleParts(env, stdlib.getT(), stdlib.getT2())));
in org.eclipse.ocl.util.OCLStandardLibraryUtil.createCollectionOperations funkction when I try to parse "Set { 1 , 2 , 5 , 88 }" body. I tried to see what are the differences in the returned values and I noticed that created tuples have the value of:
first : "<null>"
second : "<null>"
during the test and during the IDE run they have a value:
first : T
second : T2
The Error cause is NullPointer exception and stack trace is:
org.eclipse.ocl.ParserException
at org.eclipse.ocl.internal.helper.OCLHelperImpl.propagate(OCLHelperImpl.java:404)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:179)
at org.eclipse.ocl.uml.OCLHelperImpl.createQuery(OCLHelperImpl.java:91)
at org.eclipse.ocl.uml.OCLHelperImpl.createQuery(OCLHelperImpl.java:1)
at dk.dtu.imm.esculapauml.core.validators.OCLValidator.validateConstraint(OCLValidator.java:82)
at dk.dtu.imm.esculapauml.core.validators.OpaqueValidator.validateConstraint(OpaqueValidator.java:45)
at dk.dtu.imm.esculapauml.core.executors.guards.SimpleGuardEvaluator.isGuardSatisfied(SimpleGuardEvaluator.java:80)
at dk.dtu.imm.esculapauml.core.executors.guards.SimpleGuardEvaluator$1.apply(SimpleGuardEvaluator.java:42)
at dk.dtu.imm.esculapauml.core.executors.guards.SimpleGuardEvaluator$1.apply(SimpleGuardEvaluator.java:1)
at ch.lambdaj.function.matcher.Predicate$InnerMatcher.matchesSafely(Predicate.java:33)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:54)
at ch.lambdaj.function.matcher.Predicate.matches(Predicate.java:24)
at ch.lambdaj.Lambda.select(Lambda.java:302)
at ch.lambdaj.Lambda.select(Lambda.java:315)
at ch.lambdaj.Lambda.filter(Lambda.java:278)
at dk.dtu.imm.esculapauml.core.executors.guards.GuardWithElseEvaluator.getTransitionsWithEnabledGuards(GuardWithElseEvaluator.java:70)
at dk.dtu.imm.esculapauml.core.executors.BehaviorExecutor.calculateEnabledTransitions(BehaviorExecutor.java:119)
at dk.dtu.imm.esculapauml.core.executors.BehaviorExecutor.prepare(BehaviorExecutor.java:104)
at dk.dtu.imm.esculapauml.core.checkers.BehaviorChecker.registerInstance(BehaviorChecker.java:61)
at dk.dtu.imm.esculapauml.core.checkers.LifelineChecker.prepareBehaviorCheckerForLifeline(LifelineChecker.java:125)
at dk.dtu.imm.esculapauml.core.checkers.LifelineChecker.checkBehaviorExistence(LifelineChecker.java:105)
at dk.dtu.imm.esculapauml.core.checkers.LifelineChecker.structuralExistenceCheck(LifelineChecker.java:87)
at dk.dtu.imm.esculapauml.core.checkers.LifelineChecker.check(LifelineChecker.java:60)
at dk.dtu.imm.esculapauml.core.checkers.CollectionChecker.check(CollectionChecker.java:73)
at dk.dtu.imm.esculapauml.core.checkers.AbstractInteractionChecker.checkLifelines(AbstractInteractionChecker.java:40)
at dk.dtu.imm.esculapauml.core.checkers.UseCaseChecker.check(UseCaseChecker.java:42)
at dk.dtu.imm.esculapauml.core.tests.uml.GuardWithWrongValueTypeTest.guardWithWrongValueType(GuardWithWrongValueTypeTest.java:41)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at org.eclipse.ocl.uml.internal.OCLFactoryImpl.createTupleType(OCLFactoryImpl.java:153)
at org.eclipse.ocl.util.OCLStandardLibraryUtil.getTupleType(OCLStandardLibraryUtil.java:2076)
at org.eclipse.ocl.util.OCLStandardLibraryUtil.createCollectionOperations(OCLStandardLibraryUtil.java:1594)
at org.eclipse.ocl.util.OCLStandardLibraryUtil.createSetOperations(OCLStandardLibraryUtil.java:1621)
at org.eclipse.ocl.uml.internal.OCLStandardLibraryImpl.createCollectionTypeOperations(OCLStandardLibraryImpl.java:505)
at org.eclipse.ocl.uml.TypeResolverImpl.resolveCollectionType(TypeResolverImpl.java:161)
at org.eclipse.ocl.uml.TypeResolverImpl.resolveCollectionType(TypeResolverImpl.java:1)
at org.eclipse.ocl.util.TypeUtil.resolveCollectionType(TypeUtil.java:703)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionType(AbstractOCLAnalyzer.java:4560)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.getCollectionType(AbstractOCLAnalyzer.java:4532)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.collectionLiteralExpCS(AbstractOCLAnalyzer.java:3366)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.literalExpCS(AbstractOCLAnalyzer.java:3109)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.oclExpressionCS(AbstractOCLAnalyzer.java:1982)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invCS(AbstractOCLAnalyzer.java:1439)
at org.eclipse.ocl.parser.AbstractOCLAnalyzer.invOrDefCS(AbstractOCLAnalyzer.java:1419)
at org.eclipse.ocl.parser.OCLAnalyzer.parseInvOrDefCS(OCLAnalyzer.java:266)
at org.eclipse.ocl.internal.helper.HelperUtil.parseQuery(HelperUtil.java:164)
at org.eclipse.ocl.internal.helper.OCLHelperImpl.createQuery(OCLHelperImpl.java:176)
... 48 more
Please any help with this is appreciated.
Cheers,
Piotr
[Updated on: Wed, 22 February 2012 13:53] Report message to a moderator
|
|
|
Re: Null pointer exception problem with OCL parsing [message #804489 is a reply to message #804311] |
Wed, 22 February 2012 17:30 |
Ed Willink Messages: 7671 Registered: July 2009 |
Senior Member |
|
|
Hi
Well it works for "true" but fails for "Set { 1 , 2 , 5 , 88 }". "true"
is pretty easy, whereas as Set requires the creation of a synthesized
type but your failure is in the creation of the OCL Standard Library,
which is really rather hard to understand. You don't give the stack
trace so it's difficult to be more than puzzled.
Standalone usage is troublesome so perhaps your repositoryPath is
incompatible with the standalone resolution capabilities.
Perhaps you have some strange Internet connection;
https://bugs.eclipse.org/bugs/show_bug.cgi?id=364797 discusses a
potential access stupidity. You might check with Wireshark to eliminate
useless accesses.
I would check all NPEs and CCEs; EMF catches some and hides them in
Resource.errors where not everyone remembers to look for them.
Regards
Ed Willink
On 22/02/2012 13:10, Piotr J. Puczynski wrote:
> Hi.
> I am using org.eclipse.ocl_3.1.0.v20110913-1213 and
> org.eclipse.ocl.uml_3.1.0.v20110913-1213.
>
> I have a problem with OCL parsing during the JUnit tests. It seems to
> work when the IDE is lunched but it fails during the JUnit tests (as
> stand alone).
> I have two test cases ; one parses Boolean value "true" and other
> parses "Set { 1 , 2 , 5 , 88 }".
> The first does not trigger an error, second does. The context of the
> expressions is InstanceSpecification.
>
> I initialize ocl :
> System.setProperty("org.eclipse.ocl.uml", repositoryPath + "libs/ocl");
> System.setProperty("org.eclipse.uml2.uml.resources",
> repositoryPath + "libs/uml");
> String result = org.eclipse.ocl.uml.OCL.initialize(null);
> // null for global init
> assert result == null;
>
> The initialized system properties directories contain extracted
> plugins and the returned string is always null. I use null as a
> parameter but I also tried with resourceSet and usage of resurceSet in
> fact does not help.
> My code of evaluation is:
>
> UMLEnvironmentFactory envFactory = new
> UMLEnvironmentFactory(constraint.getModel().eResource().getResourceSet());
> UMLEnvironment env = envFactory.createEnvironment();
> org.eclipse.ocl.uml.OCL myOCL =
> org.eclipse.ocl.uml.OCL.newInstance(env);
> EvaluationEnvironment<?, ?, ?, ?, ?> evalEnv =
> myOCL.getEvaluationEnvironment();
> EvaluationOptions.setOption(evalEnv,
> UMLEvaluationOptions.EVALUATION_MODE, EvaluationMode.RUNTIME_OBJECTS);
> OCLExpression<?> oclConstraint = null;
> myOCL.setEvaluationTracingEnabled(true);
> myOCL.setParseTracingEnabled(true);
>
> OCLHelper<?, ?, ?, ?> helper = myOCL.createOCLHelper();
> helper.setInstanceContext(executor.getInstanceSpecification());
> String body = calculateBody();
> try {
> oclConstraint = helper.createQuery(body); //here the error
> appears
> } catch (ParserException e) {
> executor.getChecker().addOtherProblem(Diagnostic.ERROR,
> "OCL parsing exception of '" + body + "': " + e.getMessage(),
> constraint.getOwner());
> return false;
> }
> @SuppressWarnings("unchecked")
> Object result =
> myOCL.evaluate(executor.getInstanceSpecification(),
> (OCLExpression<Classifier>) oclConstraint);
>
>
> I know this type of errors can be caused by wrong initialization but I
> am doing initialization... so my ideas finished. I traced an error in
> the OCL parser code and it seem to be thrown in line
> C resultType = getSetType(env, oclFactory, getTupleType(env,
> oclFactory, createTupleParts(env, stdlib.getT(),
> stdlib.getT2())));
> in
> org.eclipse.ocl.util.OCLStandardLibraryUtil.createCollectionOperations
> funkction when I try to parse "Set { 1 , 2 , 5 , 88 }" body. I tried
> to see what are the differences in the returned values and I noticed
> that created tuples have the value of:
> first : "<null>"
> second : "<null>"
> during the test and during the IDE run they have a value:
> first : T
> second : T2
>
> Please any help with this is appreciated.
>
> Cheers,
> Piotr
|
|
| | | | |
Goto Forum:
Current Time: Thu Sep 26 23:46:58 GMT 2024
Powered by FUDForum. Page generated in 0.04440 seconds
|