Skip to content

Commit fccce54

Browse files
Fabrice Bibonnemhalbritter
authored andcommitted
Fix error mark position for PatternParseException
PatternParseException.toDetailedString() return a String with a mark to specify the error position in the pattern. The mark takes place in the second line in the String returned. Because PatternParseFailureAnalyzer.analyze appended "Invalid mapping pattern detected:" at the beginning of the returned String, the mark was not well positioned. Now, a "\n" is inserted after "Invalid mapping pattern detected:" and the mark is well positioned See gh-38944
1 parent 52a4097 commit fccce54

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/PatternParseFailureAnalyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PatternParseFailureAnalyzer extends AbstractFailureAnalyzer<PatternParseEx
3030

3131
@Override
3232
protected FailureAnalysis analyze(Throwable rootFailure, PatternParseException cause) {
33-
return new FailureAnalysis("Invalid mapping pattern detected: " + cause.toDetailedString(),
33+
return new FailureAnalysis("Invalid mapping pattern detected:\n" + cause.toDetailedString(),
3434
"Fix this pattern in your application or switch to the legacy parser implementation with "
3535
+ "'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.",
3636
cause);

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/PatternParseFailureAnalyzerTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ class PatternParseFailureAnalyzerTests {
3636
@Test
3737
void patternParseFailureQuotesPattern() {
3838
FailureAnalysis failureAnalysis = performAnalysis("/spring/**/framework");
39-
assertThat(failureAnalysis.getDescription()).contains("Invalid mapping pattern detected: /spring/**/framework");
39+
assertThat(failureAnalysis.getDescription()).contains("""
40+
Invalid mapping pattern detected:
41+
/spring/**/framework
42+
^
43+
""");
4044
assertThat(failureAnalysis.getAction())
41-
.contains("Fix this pattern in your application or switch to the legacy parser"
42-
+ " implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.");
45+
.contains("Fix this pattern in your application or switch to the legacy parser"
46+
+ " implementation with 'spring.mvc.pathmatch.matching-strategy=ant_path_matcher'.");
4347
}
4448

4549
private FailureAnalysis performAnalysis(String pattern) {

0 commit comments

Comments
 (0)