You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/07/27 17:06:48 UTC
[tomcat] branch main updated: Avoid deprecation warnings for
isAccessible
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 1bb6c6f Avoid deprecation warnings for isAccessible
1bb6c6f is described below
commit 1bb6c6fe885a266531ed4fa11619ce3eaee9e3b5
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue Jul 27 18:06:28 2021 +0100
Avoid deprecation warnings for isAccessible
Take the opportunity to simplify the code.
---
.../catalina/core/DefaultInstanceManager.java | 46 ++++++++++------------
1 file changed, 20 insertions(+), 26 deletions(-)
diff --git a/java/org/apache/catalina/core/DefaultInstanceManager.java b/java/org/apache/catalina/core/DefaultInstanceManager.java
index c82f1cc..f673334 100644
--- a/java/org/apache/catalina/core/DefaultInstanceManager.java
+++ b/java/org/apache/catalina/core/DefaultInstanceManager.java
@@ -225,13 +225,12 @@ public class DefaultInstanceManager implements InstanceManager {
AnnotationCacheEntry[] annotations = annotationCache.get(clazz);
for (AnnotationCacheEntry entry : annotations) {
if (entry.getType() == AnnotationCacheEntryType.POST_CONSTRUCT) {
+ // This will always return a new Method instance
+ // Making this instance accessible does not affect other instances
Method postConstruct = getMethod(clazz, entry);
- synchronized (postConstruct) {
- boolean accessibility = postConstruct.isAccessible();
- postConstruct.setAccessible(true);
- postConstruct.invoke(instance);
- postConstruct.setAccessible(accessibility);
- }
+ // If this doesn't work, just let invoke() fail
+ postConstruct.trySetAccessible();
+ postConstruct.invoke(instance);
}
}
}
@@ -263,13 +262,12 @@ public class DefaultInstanceManager implements InstanceManager {
}
for (AnnotationCacheEntry entry : annotations) {
if (entry.getType() == AnnotationCacheEntryType.PRE_DESTROY) {
+ // This will always return a new Method instance
+ // Making this instance accessible does not affect other instances
Method preDestroy = getMethod(clazz, entry);
- synchronized (preDestroy) {
- boolean accessibility = preDestroy.isAccessible();
- preDestroy.setAccessible(true);
- preDestroy.invoke(instance);
- preDestroy.setAccessible(accessibility);
- }
+ // If this doesn't work, just let invoke() fail
+ preDestroy.trySetAccessible();
+ preDestroy.invoke(instance);
}
}
}
@@ -572,7 +570,6 @@ public class DefaultInstanceManager implements InstanceManager {
throws NamingException, IllegalAccessException {
Object lookedupResource;
- boolean accessibility;
String normalizedName = normalize(name);
@@ -583,12 +580,11 @@ public class DefaultInstanceManager implements InstanceManager {
context.lookup(clazz.getName() + "/" + field.getName());
}
- synchronized (field) {
- accessibility = field.isAccessible();
- field.setAccessible(true);
- field.set(instance, lookedupResource);
- field.setAccessible(accessibility);
- }
+ // This will always be a new Field instance
+ // Making this instance accessible does not affect other instances
+ // If this doens't work, just let set() fail
+ field.trySetAccessible();
+ field.set(instance, lookedupResource);
}
/**
@@ -614,7 +610,6 @@ public class DefaultInstanceManager implements InstanceManager {
}
Object lookedupResource;
- boolean accessibility;
String normalizedName = normalize(name);
@@ -625,12 +620,11 @@ public class DefaultInstanceManager implements InstanceManager {
clazz.getName() + "/" + Introspection.getPropertyName(method));
}
- synchronized (method) {
- accessibility = method.isAccessible();
- method.setAccessible(true);
- method.invoke(instance, lookedupResource);
- method.setAccessible(accessibility);
- }
+ // This will always be a new Method instance
+ // Making this instance accessible does not affect other instances
+ // If this doens't work, just let invoke() fail
+ method.trySetAccessible();
+ method.invoke(instance, lookedupResource);
}
private static void loadProperties(Set<String> classNames, String resourceName,
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org