diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 48bce8e7267..59f66e5fa95 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -577,7 +577,7 @@ public class XmlConfiguration Field field = oClass.getField(attr); if (Modifier.isPublic(field.getModifiers())) { - field.set(obj, value); + setField(field, obj, value); return; } } @@ -677,7 +677,7 @@ public class XmlConfiguration { Object result = constructor.newInstance(args); if (constructor.getAnnotation(Deprecated.class) != null) - LOG.warn("Deprecated {} in {}", constructor, _url); + LOG.warn("Deprecated constructor {} in {}", constructor, _url); return result; } @@ -685,10 +685,25 @@ public class XmlConfiguration { Object result = method.invoke(obj, args); if (method.getAnnotation(Deprecated.class) != null) - LOG.warn("Deprecated {} in {}", method, _url); + LOG.warn("Deprecated method {} in {}", method, _url); return result; } + private Object getField(Field field, Object object) throws IllegalAccessException + { + Object result = field.get(object); + if (field.getAnnotation(Deprecated.class) != null) + LOG.warn("Deprecated field {} in {}", field, _url); + return result; + } + + private void setField(Field field, Object obj, Object arg) throws IllegalAccessException + { + field.set(obj, arg); + if (field.getAnnotation(Deprecated.class) != null) + LOG.warn("Deprecated field {} in {}", field, _url); + } + /** * @param array the array to convert * @param collectionType the desired collection type @@ -787,7 +802,7 @@ public class XmlConfiguration { // Try the field. Field field = oClass.getField(name); - obj = field.get(obj); + obj = getField(field, obj); configure(obj, node, 0); } catch (NoSuchFieldException nsfe) diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/AnnotatedTestConfiguration.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/AnnotatedTestConfiguration.java index d6f3ec5f482..9d1ff60db16 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/AnnotatedTestConfiguration.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/AnnotatedTestConfiguration.java @@ -27,6 +27,9 @@ public class AnnotatedTestConfiguration private String third; private String deprecated; private AnnotatedTestConfiguration nested; + // Do not remove deprecation, used in tests. + @Deprecated + public String obsolete; // Do not remove deprecation, used in tests. @Deprecated diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index e02107ffe13..44758c43023 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -993,10 +993,14 @@ public class XmlConfigurationTest @Test public void testDeprecated() throws Exception { + Class testClass = AnnotatedTestConfiguration.class; XmlConfiguration xmlConfiguration = new XmlConfiguration("" + - "" + + "" + " foo" + - " " + + " " + + " " + + " " + + " " + ""); ByteArrayOutputStream logBytes = null; @@ -1012,14 +1016,18 @@ public class XmlConfigurationTest if (logBytes != null) { - List warnings = Arrays.stream(logBytes.toString("UTF-8").split(System.lineSeparator())) - .filter(line -> line.contains(":WARN:") && line.contains("AnnotatedTestConfiguration")) + String[] lines = logBytes.toString("UTF-8").split(System.lineSeparator()); + List warnings = Arrays.stream(lines) + .filter(line -> line.contains(":WARN:")) + .filter(line -> line.contains(testClass.getSimpleName())) .collect(Collectors.toList()); // 1. Deprecated constructor - // 2. Deprecated - // 3. Deprecated - // 4. Deprecated - assertEquals(4, warnings.size()); + // 2. Deprecated method + // 3. Deprecated method + // 4. Deprecated method + // 5. Deprecated field + // 6. Deprecated field + assertEquals(6, warnings.size()); } } }