New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing non-existing variables in association specialization. #1260

Open
BernardYuan opened this Issue Apr 18, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@BernardYuan
Contributor

BernardYuan commented Apr 18, 2018

In some cases of association specialization, the _relatedSpecialization template might be instantiated into classes accessing non-existing variables.

Example:

class A{
	1 -- * C;
}
class B{
	isA A;
	1 -- 3 C;
}
class C{
}

Then the association from class B to class C is an association specialization of the association between A and C. Therefore, in generated code of class C, the existing attributes are:

  //------------------------
  // MEMBER VARIABLES
  //------------------------

  //C Associations
  private A a;

However, there are methods trying to accessing the non-existing 'b':

  /* Code from template association_GetOne_relatedSpecialization */
  public B getB_OneB()
  {
    return (B)b;
  } 

and

  /* Code from template association_set_specialization_reqCommonCode */  /* Code from template association_SetOneToAtMostN_relatedSpecialization */
  public boolean setB_B(B aB)
  {
    boolean wasSet = false;
    //Must provide b to c
    if (aB == null)
    {
      return wasSet;
    }

    //b already at maximum (3)
    if (aB.numberOfCs() >= B.maximumNumberOfCs_C())
    {
      return wasSet;
    }
    
    B existingB = (B)b;
    b = aB;
    if (existingB != null && !existingB.equals(aB))
    {
      boolean didRemove = existingB.removeC(this);
      if (!didRemove)
      {
        b = existingB;
        return wasSet;
      }
    }
    aB.addC(this);
    wasSet = true;
    return wasSet;
  }

Some parts of the Java code generator should be modified to fix this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment