You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2021/12/06 16:08:46 UTC
[sling-org-apache-sling-models-impl] branch master updated: SLING-10969 Remove synchronized blocks around injection points (#29)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-models-impl.git
The following commit(s) were added to refs/heads/master by this push:
new 6a10f56 SLING-10969 Remove synchronized blocks around injection points (#29)
6a10f56 is described below
commit 6a10f5640b276eb36d08c304cbdb3bd27b44010c
Author: paul-bjorkstrand <pa...@perficient.com>
AuthorDate: Mon Dec 6 10:06:46 2021 -0600
SLING-10969 Remove synchronized blocks around injection points (#29)
Also, remove the original cause of SLING-6584, the "reset" of the setAccessible flag.
---
.../apache/sling/models/impl/ModelAdapterFactory.java | 19 +++++--------------
.../sling/models/impl/model/InjectableField.java | 19 +++++--------------
.../models/impl/model/ModelClassConstructor.java | 15 ++-------------
3 files changed, 12 insertions(+), 41 deletions(-)
diff --git a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
index 67a4a21..fb6605e 100644
--- a/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
+++ b/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java
@@ -952,20 +952,11 @@ public class ModelAdapterFactory implements AdapterFactory, Runnable, ModelFacto
}
Collections.reverse(postConstructMethods);
for (Method method : postConstructMethods) {
- boolean accessible = method.isAccessible();
- try {
- if (!accessible) {
- method.setAccessible(true);
- }
- Object result = method.invoke(object);
- if (result instanceof Boolean && !((Boolean) result).booleanValue()) {
- log.debug("PostConstruct method {}.{} returned false. Returning null model.", method.getDeclaringClass().getName(), method.getName());
- return null;
- }
- } finally {
- if (!accessible) {
- method.setAccessible(false);
- }
+ method.setAccessible(true);
+ Object result = method.invoke(object);
+ if (result instanceof Boolean && !((Boolean) result).booleanValue()) {
+ log.debug("PostConstruct method {}.{} returned false. Returning null model.", method.getDeclaringClass().getName(), method.getName());
+ return null;
}
}
return object;
diff --git a/src/main/java/org/apache/sling/models/impl/model/InjectableField.java b/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
index ccf17d6..161b369 100644
--- a/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
+++ b/src/main/java/org/apache/sling/models/impl/model/InjectableField.java
@@ -37,20 +37,11 @@ public class InjectableField extends AbstractInjectableElement {
}
public RuntimeException set(Object createdObject, Result<Object> result) {
- synchronized (field) {
- boolean accessible = field.isAccessible();
- try {
- if (!accessible) {
- field.setAccessible(true);
- }
- field.set(createdObject, result.getValue());
- } catch (Exception e) {
- return new ModelClassException("Could not inject field due to reflection issues", e);
- } finally {
- if (!accessible) {
- field.setAccessible(false);
- }
- }
+ try {
+ field.setAccessible(true);
+ field.set(createdObject, result.getValue());
+ } catch (Exception e) {
+ return new ModelClassException("Could not inject field due to reflection issues", e);
}
return null;
}
diff --git a/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java b/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java
index 5629839..23460be 100644
--- a/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java
+++ b/src/main/java/org/apache/sling/models/impl/model/ModelClassConstructor.java
@@ -68,19 +68,8 @@ public class ModelClassConstructor<M> {
*/
@SuppressWarnings({"java:S3011","java:S1874"})
public M newInstance(Object... parameters) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- synchronized (constructor) {
- boolean accessible = constructor.isAccessible();
- try {
- if (!accessible) {
- constructor.setAccessible(true);
- }
- return constructor.newInstance(parameters);
- } finally {
- if (!accessible) {
- constructor.setAccessible(false);
- }
- }
- }
+ constructor.setAccessible(true);
+ return constructor.newInstance(parameters);
}
public Constructor<M> getConstructor() {