Browse Source

Use InvalidMimeTypeException in MimeTypeUtils#sortBySpecificity

Closes gh-31254
6.0.x
rstoyanchev 1 year ago
parent
commit
05c3ffb2fb
  1. 4
      spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java
  2. 5
      spring-core/src/test/java/org/springframework/util/MimeTypeTests.java

4
spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java

@ -362,7 +362,9 @@ public abstract class MimeTypeUtils { @@ -362,7 +362,9 @@ public abstract class MimeTypeUtils {
*/
public static <T extends MimeType> void sortBySpecificity(List<T> mimeTypes) {
Assert.notNull(mimeTypes, "'mimeTypes' must not be null");
Assert.isTrue(mimeTypes.size() <= 50, "Too many elements");
if (mimeTypes.size() >= 50) {
throw new InvalidMimeTypeException(mimeTypes.toString(), "Too many elements");
}
bubbleSort(mimeTypes, MimeType::isLessSpecific);
}

5
spring-core/src/test/java/org/springframework/util/MimeTypeTests.java

@ -451,8 +451,9 @@ class MimeTypeTests { @@ -451,8 +451,9 @@ class MimeTypeTests {
MimeType audioWave = new MimeType("audio", "wave");
MimeType audioBasicLevel = new MimeType("audio", "basic", singletonMap("level", "1"));
List<MimeType> mimeTypes = new ArrayList<>(List.of(MimeTypeUtils.ALL, audio, audioWave, audioBasic,
audioBasicLevel));
List<MimeType> mimeTypes = new ArrayList<>(
List.of(MimeTypeUtils.ALL, audio, audioWave, audioBasic, audioBasicLevel));
MimeTypeUtils.sortBySpecificity(mimeTypes);
assertThat(mimeTypes).containsExactly(audioWave, audioBasicLevel, audioBasic, audio, MimeTypeUtils.ALL);

Loading…
Cancel
Save