Skip to content

[Bug]: Guard unsafe casts on GetEObject(...) results #32

@samatstariongroup

Description

@samatstariongroup

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of the EcoreNetto
  • I have searched open and closed issues to ensure it has not already been reported

Description

  • Summary: Several SetProperties implementations cast the result of Resource.GetEObject(...) directly to a concrete type. GetEObject can fail to resolve (e.g. incomplete/cross-resource models), producing a NullReferenceException or InvalidCastException with no actionable message.
  • Affected files: ECoreNetto/ModelElement/NamedElement/Classifier/EClass.cs:186, ECoreNetto/ModelElement/NamedElement/ETypedElement.cs:139, ECoreNetto/ModelElement/NamedElement/TypedElement/StructuralFeature/EReference.cs:122
  • Proposed solution: Resolve into the base type, null-check, and either record a diagnostic (see B3) or throw a descriptive exception naming the unresolved fragment. Consider a small helper on Resource/EObject that resolves-and-validates a typed reference.
  • Acceptance criteria:
    • Unresolved references produce a clear, message-bearing error (or recorded diagnostic) rather than NullReference/InvalidCast.
    • Tests cover the unresolved and wrong-type cases for each site.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions