From 2cbba0923b17af2e29e7a8e99fa737279d11e832 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Oct 2021 12:38:06 +0200 Subject: [PATCH 1/3] Upgrade to Netty 4.1.69, Jetty 9.4.44, Kotlin 1.5.31 --- build.gradle | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 015d5c0198..8ff65cc6f4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,17 @@ plugins { id 'io.spring.dependency-management' version '1.0.11.RELEASE' apply false id 'io.spring.nohttp' version '0.0.10' - id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false + id "io.freefair.aspectj" version '6.2.0' apply false id 'org.jetbrains.dokka' version '1.5.0' apply false + id 'org.jetbrains.kotlin.jvm' version '1.5.31' apply false + id "org.jetbrains.kotlin.plugin.serialization" version "1.5.31" apply false id 'org.asciidoctor.jvm.convert' version '3.3.2' id 'org.asciidoctor.jvm.pdf' version '3.3.2' - id 'de.undercouch.download' version '4.1.2' - id "io.freefair.aspectj" version '6.2.0' apply false + id "org.unbroken-dome.xjc" version '2.0.0' apply false id "com.github.ben-manes.versions" version '0.39.0' id "com.github.johnrengelman.shadow" version '7.0.0' apply false + id 'de.undercouch.download' version '4.1.2' id "me.champeau.jmh" version "0.6.6" apply false - id "org.jetbrains.kotlin.plugin.serialization" version "1.5.30" apply false - id "org.unbroken-dome.xjc" version '2.0.0' apply false } ext { @@ -28,12 +28,12 @@ configure(allprojects) { project -> dependencyManagement { imports { mavenBom "com.fasterxml.jackson:jackson-bom:2.12.5" - mavenBom "io.netty:netty-bom:4.1.68.Final" + mavenBom "io.netty:netty-bom:4.1.69.Final" mavenBom "io.projectreactor:reactor-bom:2020.0.12" mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR10" mavenBom "io.rsocket:rsocket-bom:1.1.1" - mavenBom "org.eclipse.jetty:jetty-bom:9.4.43.v20210629" - mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.30" + mavenBom "org.eclipse.jetty:jetty-bom:9.4.44.v20210927" + mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.31" mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.5.2" mavenBom "org.jetbrains.kotlinx:kotlinx-serialization-bom:1.2.2" mavenBom "org.junit:junit-bom:5.8.1" From 0f36569d75b814a43b081d5a8036534fc1090d62 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Oct 2021 12:38:39 +0200 Subject: [PATCH 2/3] Remove dead fallback code --- .../config/FreeMarkerConfigurerBeanDefinitionParser.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java index 30b3716999..7524e63a63 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/FreeMarkerConfigurerBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -61,9 +61,6 @@ public class FreeMarkerConfigurerBeanDefinitionParser extends AbstractSingleBean for (Element childElement : childElements) { locations.add(childElement.getAttribute("location")); } - if (locations.isEmpty()) { - locations.add("/WEB-INF/"); - } builder.addPropertyValue("templateLoaderPaths", StringUtils.toStringArray(locations)); } } From b1c7f7d12732d820b144781c919351d933995424 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Oct 2021 12:48:47 +0200 Subject: [PATCH 3/3] Polishing --- .../pattern/CaptureTheRestPathElement.java | 19 +++++------ .../pattern/CaptureVariablePathElement.java | 27 ++++++++-------- .../web/util/pattern/LiteralPathElement.java | 9 +++--- .../web/util/pattern/PathPattern.java | 12 +++---- .../util/pattern/PatternParseException.java | 14 ++++---- .../web/util/pattern/RegexPathElement.java | 32 +++++++++---------- .../util/pattern/SeparatorPathElement.java | 13 ++++---- .../SingleCharWildcardedPathElement.java | 12 +++---- .../web/util/pattern/WildcardPathElement.java | 11 ++++--- .../pattern/WildcardTheRestPathElement.java | 11 ++++--- 10 files changed, 83 insertions(+), 77 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java index 4cf5959639..3ee4ff2eba 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureTheRestPathElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -83,17 +83,17 @@ class CaptureTheRestPathElement extends PathElement { } private String pathToString(int fromSegment, List pathElements) { - StringBuilder buf = new StringBuilder(); + StringBuilder sb = new StringBuilder(); for (int i = fromSegment, max = pathElements.size(); i < max; i++) { Element element = pathElements.get(i); if (element instanceof PathSegment) { - buf.append(((PathSegment)element).valueToMatch()); + sb.append(((PathSegment)element).valueToMatch()); } else { - buf.append(element.value()); + sb.append(element.value()); } } - return buf.toString(); + return sb.toString(); } @Override @@ -101,6 +101,11 @@ class CaptureTheRestPathElement extends PathElement { return 1; } + @Override + public char[] getChars() { + return ("/{*" + this.variableName + "}").toCharArray(); + } + @Override public int getWildcardCount() { return 0; @@ -117,8 +122,4 @@ class CaptureTheRestPathElement extends PathElement { return "CaptureTheRest(/{*" + this.variableName + "})"; } - @Override - public char[] getChars() { - return ("/{*"+this.variableName+"}").toCharArray(); - } } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java index 0e7b812323..856c35af98 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java @@ -35,7 +35,7 @@ class CaptureVariablePathElement extends PathElement { private final String variableName; @Nullable - private Pattern constraintPattern; + private final Pattern constraintPattern; /** @@ -55,6 +55,7 @@ class CaptureVariablePathElement extends PathElement { if (colon == -1) { // no constraint this.variableName = new String(captureDescriptor, 1, captureDescriptor.length - 2); + this.constraintPattern = null; } else { this.variableName = new String(captureDescriptor, 1, colon - 1); @@ -134,6 +135,18 @@ class CaptureVariablePathElement extends PathElement { return 1; } + @Override + public char[] getChars() { + StringBuilder sb = new StringBuilder(); + sb.append('{'); + sb.append(this.variableName); + if (this.constraintPattern != null) { + sb.append(':').append(this.constraintPattern.pattern()); + } + sb.append('}'); + return sb.toString().toCharArray(); + } + @Override public int getWildcardCount() { return 0; @@ -156,16 +169,4 @@ class CaptureVariablePathElement extends PathElement { (this.constraintPattern != null ? ":" + this.constraintPattern.pattern() : "") + "})"; } - @Override - public char[] getChars() { - StringBuilder b = new StringBuilder(); - b.append('{'); - b.append(this.variableName); - if (this.constraintPattern != null) { - b.append(':').append(this.constraintPattern.pattern()); - } - b.append('}'); - return b.toString().toCharArray(); - } - } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java index 224d5d7217..70160199f7 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/LiteralPathElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -26,14 +26,15 @@ import org.springframework.web.util.pattern.PathPattern.MatchingContext; * literal path elements 'foo', 'bar' and 'goo'. * * @author Andy Clement + * @since 5.0 */ class LiteralPathElement extends PathElement { - private char[] text; + private final char[] text; - private int len; + private final int len; - private boolean caseSensitive; + private final boolean caseSensitive; public LiteralPathElement(int pos, char[] literalText, boolean caseSensitive, char separator) { diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index 777b83720e..ba87fd6b6f 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -336,18 +336,18 @@ public class PathPattern implements Comparable { PathContainer resultPath = null; if (multipleAdjacentSeparators) { // Need to rebuild the path without the duplicate adjacent separators - StringBuilder buf = new StringBuilder(); + StringBuilder sb = new StringBuilder(); int i = startIndex; while (i < endIndex) { Element e = pathElements.get(i++); - buf.append(e.value()); + sb.append(e.value()); if (e instanceof Separator) { while (i < endIndex && (pathElements.get(i) instanceof Separator)) { i++; } } } - resultPath = PathContainer.parsePath(buf.toString(), this.pathOptions); + resultPath = PathContainer.parsePath(sb.toString(), this.pathOptions); } else if (startIndex >= endIndex) { resultPath = PathContainer.parsePath(""); @@ -491,13 +491,13 @@ public class PathPattern implements Comparable { * @return the string form of the pattern */ String computePatternString() { - StringBuilder buf = new StringBuilder(); + StringBuilder sb = new StringBuilder(); PathElement pe = this.head; while (pe != null) { - buf.append(pe.getChars()); + sb.append(pe.getChars()); pe = pe.next; } - return buf.toString(); + return sb.toString(); } @Nullable diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PatternParseException.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PatternParseException.java index 8243575963..1e49751da8 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PatternParseException.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PatternParseException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 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. @@ -66,14 +66,14 @@ public class PatternParseException extends IllegalArgumentException { * with a pointer to the error position, as well as the error message. */ public String toDetailedString() { - StringBuilder buf = new StringBuilder(); - buf.append(this.pattern).append('\n'); + StringBuilder sb = new StringBuilder(); + sb.append(this.pattern).append('\n'); for (int i = 0; i < this.position; i++) { - buf.append(' '); + sb.append(' '); } - buf.append("^\n"); - buf.append(getMessage()); - return buf.toString(); + sb.append("^\n"); + sb.append(getMessage()); + return sb.toString(); } public int getPosition() { diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java index cdbad924bb..c5cd8f588f 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java @@ -136,20 +136,19 @@ class RegexPathElement extends PathElement { if (matches) { if (isNoMorePattern()) { if (matchingContext.determineRemainingPath && - (this.variableNames.isEmpty() || textToMatch.length() > 0)) { + (this.variableNames.isEmpty() || textToMatch.length() > 0)) { matchingContext.remainingPathIndex = pathIndex + 1; matches = true; } else { // No more pattern, is there more data? // If pattern is capturing variables there must be some actual data to bind to them - matches = (pathIndex + 1) >= matchingContext.pathLength - && (this.variableNames.isEmpty() || textToMatch.length() > 0); + matches = (pathIndex + 1 >= matchingContext.pathLength) && + (this.variableNames.isEmpty() || textToMatch.length() > 0); if (!matches && matchingContext.isMatchOptionalTrailingSeparator()) { - matches = (this.variableNames.isEmpty() - || textToMatch.length() > 0) - && (pathIndex + 2) >= matchingContext.pathLength - && matchingContext.isSeparator(pathIndex + 1); + matches = (this.variableNames.isEmpty() || textToMatch.length() > 0) && + (pathIndex + 2 >= matchingContext.pathLength) && + matchingContext.isSeparator(pathIndex + 1); } } } @@ -160,11 +159,11 @@ class RegexPathElement extends PathElement { if (matches && matchingContext.extractingVariables) { // Process captures - if (this.variableNames.size() != matcher.groupCount()) { // SPR-8455 - throw new IllegalArgumentException("The number of capturing groups in the pattern segment " - + this.pattern + " does not match the number of URI template variables it defines, " - + "which can occur if capturing groups are used in a URI template regex. " - + "Use non-capturing groups instead."); + if (this.variableNames.size() != matcher.groupCount()) { // SPR-8455 + throw new IllegalArgumentException("The number of capturing groups in the pattern segment " + + this.pattern + " does not match the number of URI template variables it defines, " + + "which can occur if capturing groups are used in a URI template regex. " + + "Use non-capturing groups instead."); } for (int i = 1; i <= matcher.groupCount(); i++) { String name = this.variableNames.get(i - 1); @@ -187,6 +186,11 @@ class RegexPathElement extends PathElement { return (this.regex.length - varsLength - this.variableNames.size()); } + @Override + public char[] getChars() { + return this.regex; + } + @Override public int getCaptureCount() { return this.variableNames.size(); @@ -208,8 +212,4 @@ class RegexPathElement extends PathElement { return "Regex(" + String.valueOf(this.regex) + ")"; } - @Override - public char[] getChars() { - return this.regex; - } } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java index 19cbd3d319..b140e88b44 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/SeparatorPathElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -62,14 +62,15 @@ class SeparatorPathElement extends PathElement { return 1; } - @Override - public String toString() { - return "Separator(" + this.separator + ")"; - } - @Override public char[] getChars() { return new char[] {this.separator}; } + + @Override + public String toString() { + return "Separator(" + this.separator + ")"; + } + } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/SingleCharWildcardedPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/SingleCharWildcardedPathElement.java index 7aa748af6f..d249cf7d78 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/SingleCharWildcardedPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/SingleCharWildcardedPathElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -124,15 +124,15 @@ class SingleCharWildcardedPathElement extends PathElement { return this.len; } + @Override + public char[] getChars() { + return this.text; + } + @Override public String toString() { return "SingleCharWildcarded(" + String.valueOf(this.text) + ")"; } - @Override - public char[] getChars() { - return this.text; - } - } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardPathElement.java index 1f4f0b3e87..5413dedc79 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardPathElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -86,6 +86,11 @@ class WildcardPathElement extends PathElement { return 1; } + @Override + public char[] getChars() { + return new char[] {'*'}; + } + @Override public int getWildcardCount() { return 1; @@ -102,8 +107,4 @@ class WildcardPathElement extends PathElement { return "Wildcard(*)"; } - @Override - public char[] getChars() { - return new char[] {'*'}; - } } diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardTheRestPathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardTheRestPathElement.java index 25a72d5883..e3b83634dc 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardTheRestPathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/WildcardTheRestPathElement.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 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. @@ -47,6 +47,11 @@ class WildcardTheRestPathElement extends PathElement { return 1; } + @Override + public char[] getChars() { + return (this.separator + "**").toCharArray(); + } + @Override public int getWildcardCount() { return 1; @@ -58,8 +63,4 @@ class WildcardTheRestPathElement extends PathElement { return "WildcardTheRest(" + this.separator + "**)"; } - @Override - public char[] getChars() { - return (this.separator+"**").toCharArray(); - } }