After UML-to-Java transformation, final field arrays are initialized to a default value

Technote (troubleshooting)


Problem(Abstract)

In IBM Rational Software Architect, if you have a class in the UML model with a final field as an array of "char", the resulting field will be assigned to "null" and you will not be able to re-assign a value in the constructor.

Symptom

The following steps reproduce the problem:

  1. Create a Java project and UML model

  2. Add the Java Transformation profile to the model

  3. Add a class, Class1, to the model

  4. Add an attribute, Attrib1, and operation, Class1 (this operation will serve as the constructor), to Class1

  5. Apply the JavaArray stereotype to Attrib1

  6. Set Attrib1's Properties > Advanced > Lower Value to (0)

  7. Set Attrib1's Properties > Advanced > Upper Value to (*)

  8. Set Attrib1's Properties > General > Type to char and make sure thatQualifiers: Leaf and Qualifiers: Unique are both selected

  9. Add an in parameter, Param1, to Class1

  10. Set Param1's Properties > General > Type to String

  11. Add a UML-to-Java transformation configuration

  12. Run the transformation configuration and examine the resulting Java code

    Expected Result: Attrib1 is not initialized and appears as:


    private final char[] Attrib1;


    Actual Result: Attrib1 is initialized to null and appears as:


    private final char[] Attrib1 = null;


As a result, if you then try to assign Attrib1 to a value within the constructor as follows:


public void Class1(String Param1) {
 // begin-user-code
 // TODO Auto-generated method stub
 Attrib1 = Param1.toCharArray();
 // end-user-code
}


you will get the error message The final field Class1.Attrib1 cannot be assigned inside the code.

Cause

This has been identified as a product defect under APAR PM77224.

Resolving the problem

WORKAROUND

Edit the code manually after each transformation in order to remove the initialization.

Cross reference information
Segment Product Component Platform Version Edition
Software Development Rational Software Architect for WebSphere Software Transformation Windows 8.0.4.1, 8.5

Rate this page:

(0 users)Average rating

Document information


More support for:

Rational Software Architect
Transformation

Software version:

8.0.4.1, 8.5

Operating system(s):

Windows

Reference #:

1617659

Modified date:

2012-11-23

Translate my page

Machine Translation

Content navigation