Skip to content

Commit feff940

Browse files
committed
Improve object creation and conversion between lists and arrays
1 parent 1109c8f commit feff940

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpApiV2ProxyHttpServletRequest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,16 @@ public Enumeration<String> getParameterNames() {
298298
@Override
299299
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS") // suppressing this as according to the specs we should be returning null here if we can't find params
300300
public String[] getParameterValues(String s) {
301-
List<String> values = new ArrayList<>(Arrays.asList(getQueryParamValues(queryString, s, config.isQueryStringCaseSensitive())));
302301

302+
List<String> values = getQueryParamValuesAsList(queryString, s, config.isQueryStringCaseSensitive());
303+
304+
// copy list so we don't modifying the underlying multi-value query params
305+
if (values != null) {
306+
values = new ArrayList<>(values);
307+
} else {
308+
values = new ArrayList<>();
309+
}
310+
303311
values.addAll(Arrays.asList(getFormBodyParameterCaseInsensitive(s)));
304312

305313
if (values.size() == 0) {

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsProxyHttpServletRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,16 @@ public Enumeration<String> getParameterNames() {
370370
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS") // suppressing this as according to the specs we should be returning null here if we can't find params
371371
public String[] getParameterValues(String s) {
372372

373-
// TODO lots of back and forth arrays and lists here, sort it out!
374-
List<String> values = new ArrayList<>(Arrays.asList(getQueryParamValues(request.getMultiValueQueryStringParameters(), s, config.isQueryStringCaseSensitive())));
375-
// List<String> values = getQueryParamValuesAsList(request.getMultiValueQueryStringParameters(), s, config.isQueryStringCaseSensitive());
376373
// decode key if ALB
377374
if (request.getRequestSource() == RequestSource.ALB) {
378375
s = decodeValueIfEncoded(s);
379376
}
380377

378+
List<String> values = getQueryParamValuesAsList(request.getMultiValueQueryStringParameters(), s, config.isQueryStringCaseSensitive());
381379

380+
// copy list so we don't modifying the underlying multi-value query params
381+
values = values != null ? new ArrayList<>(values) : new ArrayList<>();
382+
382383
// decode values if ALB
383384
if (values != null && request.getRequestSource() == RequestSource.ALB) {
384385
values = values.stream().map(AwsHttpServletRequest::decodeValueIfEncoded).collect(Collectors.toList());

0 commit comments

Comments
 (0)