From 51776af45de7a900c75b855b7a0d20b490f8dc57 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 19 Feb 2019 12:34:52 +0000 Subject: [PATCH] Include source of NoSuchMethodError in its failure analysis Closes gh-15995 --- .../analyzer/NoSuchMethodFailureAnalyzer.java | 20 +++++++++++++------ .../NoSuchMethodFailureAnalyzerTests.java | 5 ++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzer.java index e213278754..dd07da5c8f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -93,11 +93,19 @@ class NoSuchMethodFailureAnalyzer extends AbstractFailureAnalyzer candidates, URL actual) { StringWriter description = new StringWriter(); PrintWriter writer = new PrintWriter(description); - writer.print("An attempt was made to call the method "); - writer.print(cause.getMessage()); - writer.print(" but it does not exist. Its class, "); - writer.print(className); - writer.println(", is available from the following locations:"); + writer.println("An attempt was made to call a method that does not" + + " exist. The attempt was made from the following location:"); + writer.println(); + writer.print(" "); + writer.println(cause.getStackTrace()[0]); + writer.println(); + writer.println("The following method did not exist:"); + writer.println(); + writer.print(" "); + writer.println(cause.getMessage()); + writer.println(); + writer.println("The method's class, " + className + + ", is available from the following locations:"); writer.println(); for (URL candidate : candidates) { writer.print(" "); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzerTests.java index a13bcfe66e..4900f6c027 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/NoSuchMethodFailureAnalyzerTests.java @@ -44,8 +44,11 @@ public class NoSuchMethodFailureAnalyzerTests { assertThat(failure).isNotNull(); FailureAnalysis analysis = new NoSuchMethodFailureAnalyzer().analyze(failure); assertThat(analysis).isNotNull(); + System.out.println(analysis.getDescription()); assertThat(analysis.getDescription()) - .contains("the method javax.servlet.ServletContext.addServlet" + .contains(NoSuchMethodFailureAnalyzerTests.class.getName() + + ".createFailure(") + .contains("javax.servlet.ServletContext.addServlet" + "(Ljava/lang/String;Ljavax/servlet/Servlet;)" + "Ljavax/servlet/ServletRegistration$Dynamic;") .contains("class, javax.servlet.ServletContext,");