Skip to content

Commit

Permalink
#29498 Fix type casting issue in getFields method.
Browse files Browse the repository at this point in the history
Updated the `getFields` method to handle instances where `PARAMETER_FIELDS` might be of type `ArrayList`. This prevents potential `ClassCastException` at runtime by checking the type before casting.
  • Loading branch information
jgambarios committed Oct 24, 2024
1 parent 6460115 commit 542414d
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -470,7 +471,12 @@ public String[] getFields(final Job job) {
return new String[0];
}

return (String[]) job.parameters().get(PARAMETER_FIELDS);
final var fields = job.parameters().get(PARAMETER_FIELDS);
if (fields instanceof ArrayList) {
return ((ArrayList<String>) fields).toArray(new String[0]);
}

return (String[]) fields;
}

/**
Expand Down

0 comments on commit 542414d

Please sign in to comment.