Open SriousTaken opened 6 years ago
Example: Bad code in class DataTypePattern
, operation move
:
ContainerShape dropShadowShape = (ContainerShape) ((ContainerShape) typeBodyShape).getContainer().getChildren().get(0);
Explanation: The executed casts are checked before the displayed code here. Ignoring these, typeBodyShape.getContainer().getChildren().get(0);
should not be used as the code .get(0)
assumes the children to get is the first one. However this can not be ensured for the lifetime of the software. Instead there should be a for-loop to search over all getContainer().getChildren()
for a specific Id. See the good example for reference.
Example: Good solution in class DataTypePattern
, operation update
:
for(Shape shape : containerShape.getChildren()) {
...
if(UIUtil.isShape_IdValue(shape, literals.SHAPE_ID_DATATYPE_NAME)) {
text.setValue(businessTypeName);
returnValue = true;
} }
Sometimes in the code a reference to one container child is staticly coded. This means something like containerChildren.get(0). This should be refactored and replace with a for loop asking for the property shape id of the found child.