Skip to content

Commit

Permalink
MR: Clone ANYWHERE location array IcebergSplit (apache#4984)
Browse files Browse the repository at this point in the history
`IcebergSplit.ANYWHERE` was a mutable and publicly accessible field, so
someone could modify it. The modification could also be accidental, if
someone modified the array returned from `IcebergSplit.locations()`.
  • Loading branch information
findepi authored Jun 28, 2022
1 parent 612fa2d commit 7a783b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// and v2 file formats.
public class IcebergSplit extends InputSplit implements org.apache.hadoop.mapred.InputSplit, IcebergSplitContainer {

public static final String[] ANYWHERE = new String[]{"*"};
private static final String[] ANYWHERE = new String[]{"*"};

private Table table;
private CombinedScanTask task;
Expand Down Expand Up @@ -73,9 +73,9 @@ public String[] getLocations() {
// getLocations() won't be accurate when called on worker nodes and will always return "*"
if (locations == null && conf != null) {
boolean localityPreferred = conf.getBoolean(InputFormatConfig.LOCALITY, false);
locations = localityPreferred ? Util.blockLocations(task, conf) : ANYWHERE;
locations = localityPreferred ? Util.blockLocations(task, conf) : ANYWHERE.clone();
} else {
locations = ANYWHERE;
locations = ANYWHERE.clone();
}

return locations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void testLocality() throws Exception {
helper.appendToTable(null, expectedRecords);

for (InputSplit split : testInputFormat.create(builder.conf()).getSplits()) {
Assert.assertArrayEquals(IcebergSplit.ANYWHERE, split.getLocations());
Assert.assertArrayEquals(new String[]{"*"}, split.getLocations());
}

builder.preferLocality();
Expand Down

0 comments on commit 7a783b6

Please sign in to comment.