osate / osate2

Open Source AADL2 Tool Environment
http://osate.org
Eclipse Public License 2.0
36 stars 8 forks source link

Check for null containing classifier in Aadl2LinkingService::getLinkedObjects #2139

Closed brlarson closed 4 years ago

brlarson commented 4 years ago

Summary

When linking inside an annex library, a NullPointerException is thrown because line 224: aadl Classifier ns = AadlUtil.getContainingClassifier(context); returns null, because there is no containing classifier for an annex library.

Please check for (ns != null) before use and return an empty list instead (line 249)

  if (ns != null)
    {
    EObject searchResult = AadlUtil.findNamedElementInList(ns.getAllFeatures(), name);
    if (searchResult != null && searchResult instanceof Port)
      {
      return Collections.singletonList(searchResult);
      }
    }
  return Collections.<EObject> emptyList();

Environment

lwrage commented 4 years ago

The implementation of Aadl2LinkingService.getLinkedObjects() assumes in many places that it is only called in the context of core AADL. The name resolution for references inside any annex must happen in an annex specific linking service. The real bug is that the Aadl2LinkingService tries to resolve references inside an annex if

instead of just returning an empty list in these cases.