Skip to content

Commit e2d06ea

Browse files
committed
Deprecate outdated abstractions/delegates in core/util
Issue: SPR-15159
1 parent fcfacd9 commit e2d06ea

File tree

7 files changed

+48
-29
lines changed

7 files changed

+48
-29
lines changed

spring-aop/src/main/java/org/springframework/aop/support/ControlFlowPointcut.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,8 +22,6 @@
2222
import org.springframework.aop.ClassFilter;
2323
import org.springframework.aop.MethodMatcher;
2424
import org.springframework.aop.Pointcut;
25-
import org.springframework.core.ControlFlow;
26-
import org.springframework.core.ControlFlowFactory;
2725
import org.springframework.util.Assert;
2826
import org.springframework.util.ObjectUtils;
2927

@@ -34,7 +32,7 @@
3432
*
3533
* @author Rod Johnson
3634
* @author Rob Harrop
37-
* @see org.springframework.core.ControlFlow
35+
* @author Juergen Hoeller
3836
*/
3937
@SuppressWarnings("serial")
4038
public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher, Serializable {
@@ -43,7 +41,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
4341

4442
private String methodName;
4543

46-
private int evaluations;
44+
private volatile int evaluations;
4745

4846

4947
/**
@@ -55,11 +53,11 @@ public ControlFlowPointcut(Class<?> clazz) {
5553
}
5654

5755
/**
58-
* Construct a new pointcut that matches all calls below the
59-
* given method in the given class. If the method name is null,
60-
* matches all control flows below that class.
56+
* Construct a new pointcut that matches all calls below the given method
57+
* in the given class. If no method name is given, matches all control flows
58+
* below the given class.
6159
* @param clazz the clazz
62-
* @param methodName the name of the method
60+
* @param methodName the name of the method (may be {@code null})
6361
*/
6462
public ControlFlowPointcut(Class<?> clazz, String methodName) {
6563
Assert.notNull(clazz, "Class must not be null");
@@ -93,8 +91,14 @@ public boolean isRuntime() {
9391
@Override
9492
public boolean matches(Method method, Class<?> targetClass, Object... args) {
9593
this.evaluations++;
96-
ControlFlow cflow = ControlFlowFactory.createControlFlow();
97-
return (this.methodName != null ? cflow.under(this.clazz, this.methodName) : cflow.under(this.clazz));
94+
95+
for (StackTraceElement element : new Throwable().getStackTrace()) {
96+
if (element.getClassName().equals(this.clazz.getName()) &&
97+
(this.methodName == null || element.getMethodName().equals(this.methodName))) {
98+
return true;
99+
}
100+
}
101+
return false;
98102
}
99103

100104
/**
@@ -130,8 +134,7 @@ public boolean equals(Object other) {
130134

131135
@Override
132136
public int hashCode() {
133-
int code = 17;
134-
code = 37 * code + this.clazz.hashCode();
137+
int code = this.clazz.hashCode();
135138
if (this.methodName != null) {
136139
code = 37 * code + this.methodName.hashCode();
137140
}

spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,17 +18,15 @@
1818

1919
import java.beans.PropertyChangeEvent;
2020

21-
import org.springframework.core.ErrorCoded;
22-
2321
/**
2422
* Superclass for exceptions related to a property access,
2523
* such as type mismatch or invocation target exception.
2624
*
2725
* @author Rod Johnson
2826
* @author Juergen Hoeller
2927
*/
30-
@SuppressWarnings("serial")
31-
public abstract class PropertyAccessException extends BeansException implements ErrorCoded {
28+
@SuppressWarnings({"serial", "deprecation"})
29+
public abstract class PropertyAccessException extends BeansException implements org.springframework.core.ErrorCoded {
3230

3331
private transient PropertyChangeEvent propertyChangeEvent;
3432

@@ -77,4 +75,10 @@ public Object getValue() {
7775
return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getNewValue() : null);
7876
}
7977

78+
/**
79+
* Return a corresponding error code for this type of exception.
80+
*/
81+
@Override
82+
public abstract String getErrorCode();
83+
8084
}

spring-core/src/main/java/org/springframework/core/ControlFlow.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,9 @@
2323
*
2424
* @author Rod Johnson
2525
* @since 02.02.2004
26+
* @deprecated as of Spring Framework 4.3.6
2627
*/
28+
@Deprecated
2729
public interface ControlFlow {
2830

2931
/**

spring-core/src/main/java/org/springframework/core/ControlFlowFactory.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,9 @@
3131
* @author Rod Johnson
3232
* @author Juergen Hoeller
3333
* @since 02.02.2004
34+
* @deprecated as of Spring Framework 4.3.6
3435
*/
36+
@Deprecated
3537
public abstract class ControlFlowFactory {
3638

3739
/**
@@ -65,8 +67,8 @@ public Jdk14ControlFlow() {
6567
public boolean under(Class<?> clazz) {
6668
Assert.notNull(clazz, "Class must not be null");
6769
String className = clazz.getName();
68-
for (int i = 0; i < stack.length; i++) {
69-
if (this.stack[i].getClassName().equals(className)) {
70+
for (StackTraceElement element : this.stack) {
71+
if (element.getClassName().equals(className)) {
7072
return true;
7173
}
7274
}
@@ -82,9 +84,9 @@ public boolean under(Class<?> clazz, String methodName) {
8284
Assert.notNull(clazz, "Class must not be null");
8385
Assert.notNull(methodName, "Method name must not be null");
8486
String className = clazz.getName();
85-
for (int i = 0; i < this.stack.length; i++) {
86-
if (this.stack[i].getClassName().equals(className) &&
87-
this.stack[i].getMethodName().equals(methodName)) {
87+
for (StackTraceElement element : this.stack) {
88+
if (element.getClassName().equals(className) &&
89+
element.getMethodName().equals(methodName)) {
8890
return true;
8991
}
9092
}
@@ -103,7 +105,7 @@ public boolean underToken(String token) {
103105
StringWriter sw = new StringWriter();
104106
new Throwable().printStackTrace(new PrintWriter(sw));
105107
String stackTrace = sw.toString();
106-
return stackTrace.indexOf(token) != -1;
108+
return stackTrace.contains(token);
107109
}
108110

109111
@Override

spring-core/src/main/java/org/springframework/core/ErrorCoded.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,9 @@
2525
*
2626
* @author Rod Johnson
2727
* @see org.springframework.context.MessageSource
28+
* @deprecated as of Spring Framework 4.3.6
2829
*/
30+
@Deprecated
2931
public interface ErrorCoded {
3032

3133
/**

spring-core/src/main/java/org/springframework/util/WeakReferenceMonitor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,9 @@
4444
* @author Juergen Hoeller
4545
* @since 1.2
4646
* @see #monitor
47+
* @deprecated as of Spring Framework 4.3.6
4748
*/
49+
@Deprecated
4850
public class WeakReferenceMonitor {
4951

5052
private static final Log logger = LogFactory.getLog(WeakReferenceMonitor.class);

spring-core/src/test/java/org/springframework/core/ControlFlowTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
* @author Rod Johnson
2525
* @author Sam Brannen
2626
*/
27+
@SuppressWarnings("deprecation")
2728
public class ControlFlowTests {
2829

2930
@Test
@@ -33,6 +34,7 @@ public void underClassAndMethod() {
3334
new Three().test();
3435
}
3536

37+
3638
static class One {
3739

3840
void test() {
@@ -45,6 +47,7 @@ void test() {
4547
}
4648
}
4749

50+
4851
static class Two {
4952

5053
void testing() {
@@ -57,6 +60,7 @@ void testing() {
5760
}
5861
}
5962

63+
6064
static class Three {
6165

6266
void test() {

0 commit comments

Comments
 (0)