EMF Validation, Java 8 and nsURI

aurelien.pupier
Blog Categories: 

After migrating to Eclipse 4.4, and with the support of Java 8 working well, it is time to launch our full test suite on Java 8! Unfortunately, one test for an EMF Validation was failing. It took me quite some time to figure out what went wrong, but the fix is quite easy and it would have never happened if a simple best practice rule was used.

In short:

ALWAYS specify nsURI !

Technical details on the issue

If nsURI is not specified, the framework takes the first EClass with the corresponding name. In my case, there was a conflict with GMF Notation. There were two EClass named Connector. Until Java 8, it was always my EClass which was used so I never detected the potential issue. With Java 8, it is always the GMF one.

Details on how to solve the issue

When defining the target EClass, specify the nsURI following the convention explained in the tooltip :
WithoutnsURISPecified

Please note that in most cases, though not in mine :-(, a constraint applies to a single model namespace. In this case you would be able to specify a package at the constraint provider level which will avoid the issue.
namespaceURICOntraintProvider

Going further

It would be nice to warn the user when there are two elements found instead of simply taking the first one. This validation might be done both at runtime and at design time.

When specifying the nsURI, the extension point defined is not easily readable directly in the tree:
WithNsURIDisplayIssue

I opened an enhancement request to prevent issues like this and to improve usability. I proposed several solutions, and your ideas are highly welcome.

Acknowledgement

Warm thanks to Christian W. Damus for his help on the Eclipse forum as I investigated this issue.

Notifications