locationtech / udig-platform

uDig parent project containing all core components. More plugins can be found in community repos: http://github.com/uDig-Community
http://udig.refractions.net
190 stars 133 forks source link

Fix bug in if-condition #639

Closed sschulz92 closed 2 years ago

sschulz92 commented 2 years ago

The fix is hidden by the code-formatter, to clearify I changed the following part on purpose:

Old code:

AttributeType originalAttributeType = originalFeatureType.getType(name);
if (originalAttributeType == null
        && originalAttributeType instanceof GeometryType) {
    crs = ((GeometryType) originalAttributeType).getCoordinateReferenceSystem();
} else {
    crs = originalFeatureType.getCoordinateReferenceSystem();
}

New code:

AttributeType originalAttributeType = originalFeatureType.getType(name);
if (originalAttributeType != null
        && originalAttributeType instanceof GeometryType) {
    crs = ((GeometryType) originalAttributeType).getCoordinateReferenceSystem();
} else {
    crs = originalFeatureType.getCoordinateReferenceSystem();
}

Note the switch from == null towards != null.

This will solve a SonarQube issue also, which detects this bug basically.

fgdrf commented 2 years ago

Thanks a ton for this potential NullPointerException!