Don't throw NPE if accessing null references#10
Don't throw NPE if accessing null references#10abstraktor wants to merge 1 commit intomodelix:mainfrom
Conversation
Given I have a concept `Car` which has a nullable reference `owner`
And my `aCar` has no owner
When I call `aCar.getOwner()`, I erroneously got a NullPointerException
Because it is calling `MPSLanguageRegistry.Companion.getInstance(getINode().getReferenceTarget("owner"))`
It now returns null instead of throwing the NPE
|
I don't think we should solve this in the registry. You must never pass null into the registry. I think we should change the code generator. Right now it emits this code when the reference has a cardinality of 1 if the reference is I think we need a switch in the code generator which allows for incomplete models and then makes basically everything |
|
The cardinality is just a convenient way to specify a constraint that can be used by the editor or model checker, but nothing you can enforce on API level. For convenience you could generate an additional method that does the null check and throws a meaningful exception, but I think you always need the method that allows you to read the "raw" value of a reference. |
thanks to christoph and sameh for debugging this together