From e2d06eaae5486338bb17b584056ed8e2e6218ede Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 23 Jan 2017 23:47:14 +0100 Subject: [PATCH] Deprecate outdated abstractions/delegates in core/util Issue: SPR-15159 --- .../aop/support/ControlFlowPointcut.java | 29 ++++++++++--------- .../beans/PropertyAccessException.java | 14 +++++---- .../org/springframework/core/ControlFlow.java | 4 ++- .../core/ControlFlowFactory.java | 16 +++++----- .../org/springframework/core/ErrorCoded.java | 4 ++- .../util/WeakReferenceMonitor.java | 4 ++- .../core/ControlFlowTests.java | 6 +++- 7 files changed, 48 insertions(+), 29 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java index 1989a6dae41..47d201cfcd0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -22,8 +22,6 @@ import java.lang.reflect.Method; import org.springframework.aop.ClassFilter; import org.springframework.aop.MethodMatcher; import org.springframework.aop.Pointcut; -import org.springframework.core.ControlFlow; -import org.springframework.core.ControlFlowFactory; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -34,7 +32,7 @@ import org.springframework.util.ObjectUtils; * * @author Rod Johnson * @author Rob Harrop - * @see org.springframework.core.ControlFlow + * @author Juergen Hoeller */ @SuppressWarnings("serial") public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher, Serializable { @@ -43,7 +41,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher private String methodName; - private int evaluations; + private volatile int evaluations; /** @@ -55,11 +53,11 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher } /** - * Construct a new pointcut that matches all calls below the - * given method in the given class. If the method name is null, - * matches all control flows below that class. + * Construct a new pointcut that matches all calls below the given method + * in the given class. If no method name is given, matches all control flows + * below the given class. * @param clazz the clazz - * @param methodName the name of the method + * @param methodName the name of the method (may be {@code null}) */ public ControlFlowPointcut(Class clazz, String methodName) { Assert.notNull(clazz, "Class must not be null"); @@ -93,8 +91,14 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher @Override public boolean matches(Method method, Class targetClass, Object... args) { this.evaluations++; - ControlFlow cflow = ControlFlowFactory.createControlFlow(); - return (this.methodName != null ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz)); + + for (StackTraceElement element : new Throwable().getStackTrace()) { + if (element.getClassName().equals(this.clazz.getName()) && + (this.methodName == null || element.getMethodName().equals(this.methodName))) { + return true; + } + } + return false; } /** @@ -130,8 +134,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher @Override public int hashCode() { - int code = 17; - code = 37 * code + this.clazz.hashCode(); + int code = this.clazz.hashCode(); if (this.methodName != null) { code = 37 * code + this.methodName.hashCode(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java index 68bdde7412f..61cb509a86e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -18,8 +18,6 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; -import org.springframework.core.ErrorCoded; - /** * Superclass for exceptions related to a property access, * such as type mismatch or invocation target exception. @@ -27,8 +25,8 @@ import org.springframework.core.ErrorCoded; * @author Rod Johnson * @author Juergen Hoeller */ -@SuppressWarnings("serial") -public abstract class PropertyAccessException extends BeansException implements ErrorCoded { +@SuppressWarnings({"serial", "deprecation"}) +public abstract class PropertyAccessException extends BeansException implements org.springframework.core.ErrorCoded { private transient PropertyChangeEvent propertyChangeEvent; @@ -77,4 +75,10 @@ public abstract class PropertyAccessException extends BeansException implements return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getNewValue() : null); } + /** + * Return a corresponding error code for this type of exception. + */ + @Override + public abstract String getErrorCode(); + } diff --git a/spring-core/src/main/java/org/springframework/core/ControlFlow.java b/spring-core/src/main/java/org/springframework/core/ControlFlow.java index a650c6cb400..860d57c09f9 100644 --- a/spring-core/src/main/java/org/springframework/core/ControlFlow.java +++ b/spring-core/src/main/java/org/springframework/core/ControlFlow.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -23,7 +23,9 @@ package org.springframework.core; * * @author Rod Johnson * @since 02.02.2004 + * @deprecated as of Spring Framework 4.3.6 */ +@Deprecated public interface ControlFlow { /** diff --git a/spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java b/spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java index 167de0f7e00..2287d97b450 100644 --- a/spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java +++ b/spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -31,7 +31,9 @@ import org.springframework.util.Assert; * @author Rod Johnson * @author Juergen Hoeller * @since 02.02.2004 + * @deprecated as of Spring Framework 4.3.6 */ +@Deprecated public abstract class ControlFlowFactory { /** @@ -65,8 +67,8 @@ public abstract class ControlFlowFactory { public boolean under(Class clazz) { Assert.notNull(clazz, "Class must not be null"); String className = clazz.getName(); - for (int i = 0; i < stack.length; i++) { - if (this.stack[i].getClassName().equals(className)) { + for (StackTraceElement element : this.stack) { + if (element.getClassName().equals(className)) { return true; } } @@ -82,9 +84,9 @@ public abstract class ControlFlowFactory { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); String className = clazz.getName(); - for (int i = 0; i < this.stack.length; i++) { - if (this.stack[i].getClassName().equals(className) && - this.stack[i].getMethodName().equals(methodName)) { + for (StackTraceElement element : this.stack) { + if (element.getClassName().equals(className) && + element.getMethodName().equals(methodName)) { return true; } } @@ -103,7 +105,7 @@ public abstract class ControlFlowFactory { StringWriter sw = new StringWriter(); new Throwable().printStackTrace(new PrintWriter(sw)); String stackTrace = sw.toString(); - return stackTrace.indexOf(token) != -1; + return stackTrace.contains(token); } @Override diff --git a/spring-core/src/main/java/org/springframework/core/ErrorCoded.java b/spring-core/src/main/java/org/springframework/core/ErrorCoded.java index 1425fe8492a..a0e1ba63905 100644 --- a/spring-core/src/main/java/org/springframework/core/ErrorCoded.java +++ b/spring-core/src/main/java/org/springframework/core/ErrorCoded.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -25,7 +25,9 @@ package org.springframework.core; * * @author Rod Johnson * @see org.springframework.context.MessageSource + * @deprecated as of Spring Framework 4.3.6 */ +@Deprecated public interface ErrorCoded { /** diff --git a/spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java b/spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java index 1a486757264..8e83bd9eb5f 100644 --- a/spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java +++ b/spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -44,7 +44,9 @@ import org.apache.commons.logging.LogFactory; * @author Juergen Hoeller * @since 1.2 * @see #monitor + * @deprecated as of Spring Framework 4.3.6 */ +@Deprecated public class WeakReferenceMonitor { private static final Log logger = LogFactory.getLog(WeakReferenceMonitor.class); diff --git a/spring-core/src/test/java/org/springframework/core/ControlFlowTests.java b/spring-core/src/test/java/org/springframework/core/ControlFlowTests.java index 7272e914e5a..0b485941f6f 100644 --- a/spring-core/src/test/java/org/springframework/core/ControlFlowTests.java +++ b/spring-core/src/test/java/org/springframework/core/ControlFlowTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2017 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. @@ -24,6 +24,7 @@ import static org.junit.Assert.*; * @author Rod Johnson * @author Sam Brannen */ +@SuppressWarnings("deprecation") public class ControlFlowTests { @Test @@ -33,6 +34,7 @@ public class ControlFlowTests { new Three().test(); } + static class One { void test() { @@ -45,6 +47,7 @@ public class ControlFlowTests { } } + static class Two { void testing() { @@ -57,6 +60,7 @@ public class ControlFlowTests { } } + static class Three { void test() {