Skip to content

Commit 9054f4f

Browse files
committed
HttpHeaders fails getAllow if set to EmptyCollection
Prior to this commit, calls to getAllow would fail is setAllow was set to an EmptyCollection right before. java.lang.IllegalArgumentException: No enum constant org.springframework.http.HttpMethod This commit fixes this by testing the header value for an empty value before trying to use it to get a value from the Enum. Issue: SPR-11917 (cherry picked from commit 9919a98)
1 parent 41e78d0 commit 9054f4f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void setAllow(Set<HttpMethod> allowedMethods) {
224224
*/
225225
public Set<HttpMethod> getAllow() {
226226
String value = getFirst(ALLOW);
227-
if (value != null) {
227+
if (!StringUtils.isEmpty(value)) {
228228
List<HttpMethod> allowedMethod = new ArrayList<HttpMethod>(5);
229229
String[] tokens = value.split(",\\s*");
230230
for (String token : tokens) {

spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,18 +22,23 @@
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
2424
import java.util.Calendar;
25+
import java.util.Collections;
2526
import java.util.EnumSet;
2627
import java.util.GregorianCalendar;
2728
import java.util.List;
2829
import java.util.Locale;
30+
import java.util.Set;
2931
import java.util.TimeZone;
3032

33+
import org.hamcrest.Matchers;
3134
import org.junit.Before;
3235
import org.junit.Test;
3336

3437
import static org.junit.Assert.*;
3538

36-
/** @author Arjen Poutsma */
39+
/**
40+
* @author Arjen Poutsma
41+
*/
3742
public class HttpHeadersTests {
3843

3944
private HttpHeaders headers;
@@ -256,5 +261,13 @@ public void contentDisposition() {
256261
headers.getFirst("Content-Disposition"));
257262
}
258263

264+
// SPR-11917
265+
266+
@Test
267+
public void getAllowEmptySet() {
268+
headers.setAllow(Collections.<HttpMethod> emptySet());
269+
270+
assertThat(headers.getAllow(), Matchers.emptyCollectionOf(HttpMethod.class));
271+
}
259272

260273
}

0 commit comments

Comments
 (0)