Fix IllegalStateException in empty ProducesRequestCondition

When comparing empty ProducesRequestCondition, compareTo would throw an
IllegalStateException if the Accept header was invalid. This commit
fixes that behavior.

Closes gh-29794
This commit is contained in:
Arjen Poutsma
2023-01-18 10:38:09 +01:00
parent 64de6de725
commit 9ebd1e8d64
4 changed files with 33 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -309,6 +309,17 @@ public class ProducesRequestConditionTests {
assertThat(result > 0).as("Should have used MediaType.equals(Object) to break the match").isTrue();
}
@Test
public void compareEmptyInvalidAccept() {
HttpServletRequest request = createRequest("foo");
ProducesRequestCondition condition1 = new ProducesRequestCondition();
ProducesRequestCondition condition2 = new ProducesRequestCondition();
int result = condition1.compareTo(condition2, request);
assertThat(result).isEqualTo(0);
}
@Test
public void combine() {
ProducesRequestCondition condition1 = new ProducesRequestCondition("text/plain");