Bug 447905 - NPE on helper without operation body
Summary: NPE on helper without operation body
Status: NEW
Alias: None
Product: QVTo
Classification: Modeling
Component: Engine (show other bugs)
Version: 3.4.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-20 08:05 EDT by Christopher Gerking CLA
Modified: 2014-10-21 04:54 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Gerking CLA 2014-10-20 08:05:07 EDT
A helper without an operation body results in an NPE, which is certainly not the intended behavior.

Should it return null instead? Should there be a compile error? Can the 'abstract' keyword help do distinguish legal from erroneous declarations?
Comment 1 Christopher Gerking CLA 2014-10-20 08:13:56 EDT
Maybe the discussions on bug 428028 or bug 428189 provide some hints on how to handle this case?
Comment 2 Christopher Gerking CLA 2014-10-20 08:23:54 EDT
Furthermore, I wonder why this case doesn't at least produce 'invalid', as intended for bug 415660. The reason is that QvtOperationalEvaluationVisitorImpl catches RuntimeException in executeImperativeOperation() and converts it into a QvtRuntimeException which bypasses the conversion to 'invalid'. I'm not sure if this behavior is appropriate.
Comment 3 Ed Willink CLA 2014-10-21 03:06:25 EDT
bug 428189 discussed body-less mappings rather than helpers, but helpers too can be a polymorphic hierarchy.

My normal expectation, from C/C++, is that a bodyless definition is a forward declaration that resolves parsing difficulties or an external declaration.

Forward referencing is unspecified in QVTo, but many statements in OCL/QVT only make sense as the ultimate truth of the parsing/analysis, so I take the view that there is no prohibition on forward references in QVT and so no need for pre-declarations.

Therefore a bodyless mapping is either a typo for a missing 'blackbox' or a typo for an empty body.

Since the current behavior is NPE, backward compatibility is not a problem.

Suggest:

at run time, empty non-blackbox helper body returns invalid.

at compile time empty non-abstract non-blackbox helper body is a warning, ideally offering 'abstract' or 'blackbox' or '{}' as quickfixes.

If/when we have a strict option, change the warning to error.
Comment 4 Ed Willink CLA 2014-10-21 03:20:06 EDT
(In reply to Ed Willink from comment #3)
> at run time, empty non-blackbox helper body returns invalid.

Except that, see Bug 440813, when used in an imperative context a to-be-specified exception should be thrown.
Comment 5 Christopher Gerking CLA 2014-10-21 03:23:12 EDT
By the way, does OCL provide semantics for 'abstract' operations? QVTo seems not, and I still wonder if the implemented behavior for abstract mappings (i.e. may have a body, but must not be invoked directly, only merged/inherited) is profound or just a guess.
Comment 6 Ed Willink CLA 2014-10-21 04:54:39 EDT
The semantics of operation overloading and dispatch are left as a variation point in UML and are not specified in UML, leaving both UML and OCL with a gaping hole.

In various discussions I have found no objections to using Java-like semantics. The Ecore-based OCL has an evaluation preference to select dynamic dispatch. The Pivot-based OCL only supports dynamic dispatch, with the extra elaboration that OclSelf may be used in a type signature so that Real::"-"(OclSelf) automatiocally dispatches to Real::"-"(OclSelf) or Integer::"-"(OclSelf) according to the common type of two arguments.

I hope that QVT ?2.x will clarify in similar fashion, with the slight proviso that the Package behavior of xxxTransformation may vanish in favour of a clean Class inheritance. xxxTransformation should be nested within one of more Packages to establish name qualification.