-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingpriority:majorMajor loss of functionMajor loss of function
Milestone
Description
Guillaume Nodet opened MNG-8350 and commented
The Build constructor has the following code:
Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
mutableLocations.put("sourceDirectory", newlocs.containsKey("sourceDirectory") ? newlocs.get("sourceDirectory") : oldlocs.get("sourceDirectory"));
mutableLocations.put("scriptSourceDirectory", newlocs.containsKey("scriptSourceDirectory") ? newlocs.get("scriptSourceDirectory") : oldlocs.get("scriptSourceDirectory"));
mutableLocations.put("testSourceDirectory", newlocs.containsKey("testSourceDirectory") ? newlocs.get("testSourceDirectory") : oldlocs.get("testSourceDirectory"));
mutableLocations.put("outputDirectory", newlocs.containsKey("outputDirectory") ? newlocs.get("outputDirectory") : oldlocs.get("outputDirectory"));
mutableLocations.put("testOutputDirectory", newlocs.containsKey("testOutputDirectory") ? newlocs.get("testOutputDirectory") : oldlocs.get("testOutputDirectory"));
mutableLocations.put("extensions", newlocs.containsKey("extensions") ? newlocs.get("extensions") : oldlocs.get("extensions"));
this.locations = Collections.unmodifiableMap(mutableLocations);
This is inefficient, especially when building models programmatically, in which cases locations are usually not set. The code will always store a null value for each key, whereas an empty map could be sufficient if there's no actual values.
The generator code is located at:
Lines 174 to 186 in b370e5e
| Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap(); | |
| Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap(); | |
| #if ( ! $class.superClass ) | |
| Map<Object, InputLocation> mutableLocations = new HashMap<>(); | |
| this.importedFrom = builder.importedFrom; | |
| mutableLocations.put("", newlocs.containsKey("") ? newlocs.get("") : oldlocs.get("")); | |
| #else | |
| Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations); | |
| #end | |
| #foreach ( $field in $class.getFields($version) ) | |
| mutableLocations.put("${field.name}", newlocs.containsKey("${field.name}") ? newlocs.get("${field.name}") : oldlocs.get("${field.name}")); | |
| #end | |
| this.locations = Collections.unmodifiableMap(mutableLocations); |
Affects: 4.0.0-beta-5
Remote Links:
Backported to: 4.0.0-rc-1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingpriority:majorMajor loss of functionMajor loss of function