[ https://issues.apache.org/jira/browse/SLING-6584?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Justin Edelson closed SLING-6584. --------------------------------- > Race condition in ModelAdapterFactory > ------------------------------------- > > Key: SLING-6584 > URL: https://issues.apache.org/jira/browse/SLING-6584 > Project: Sling > Issue Type: Bug > Components: Extensions > Affects Versions: Sling Models Impl 1.3.8 > Reporter: Vlad Bailescu > Assignee: Justin Edelson > Priority: Critical > Fix For: Sling Models Impl 1.4.0 > > Attachments: SLING-6584.test.patch > > > There is a possible race condition in > https://github.com/apache/sling/blob/trunk/bundles/extensions/models/impl/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L807-L815 > when two threads are trying to inject the same field, resulting in model not > being constructed. > {code} > 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); > } > } > {code} > This is exposed by the unit test attached: > {code} > org.apache.sling.models.impl.ModelAdapterFactory - Could not adapt to model > org.apache.sling.models.factory.MissingElementsException: Could not inject > all required fields into class > org.apache.sling.models.testmodels.classes.WithOneConstructorModel > at > org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:593) > at > org.apache.sling.models.impl.ModelAdapterFactory.internalCreateModel(ModelAdapterFactory.java:335) > at > org.apache.sling.models.impl.ModelAdapterFactory.getAdapter(ModelAdapterFactory.java:211) > at > org.apache.sling.models.impl.ConstructorTest$1ModelCreator.call(ConstructorTest.java:153) > at > org.apache.sling.models.impl.ConstructorTest$1ModelCreator.call(ConstructorTest.java:149) > at java.util.concurrent.FutureTask.run(FutureTask.java:266) > at > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) > at > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) > at java.lang.Thread.run(Thread.java:745) > Suppressed: org.apache.sling.models.factory.MissingElementException: > Could not inject private int > org.apache.sling.models.testmodels.classes.WithOneConstructorModel.attribute > at > org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:598) > ... 8 more > Caused by: org.apache.sling.models.factory.ModelClassException: Could > not inject field due to reflection issues > at > org.apache.sling.models.impl.ModelAdapterFactory.setField(ModelAdapterFactory.java:812) > at > org.apache.sling.models.impl.ModelAdapterFactory.access$100(ModelAdapterFactory.java:112) > at > org.apache.sling.models.impl.ModelAdapterFactory$SetFieldCallback.inject(ModelAdapterFactory.java:378) > at > org.apache.sling.models.impl.ModelAdapterFactory.injectElement(ModelAdapterFactory.java:473) > at > org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:596) > ... 8 more > Caused by: java.lang.IllegalAccessException: Class > org.apache.sling.models.impl.ModelAdapterFactory can not access a member of > class org.apache.sling.models.testmodels.classes.WithOneConstructorModel with > modifiers "private" > at > sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101) > at > java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:295) > at > java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:287) > at java.lang.reflect.Field.set(Field.java:755) > at > org.apache.sling.models.impl.ModelAdapterFactory.setField(ModelAdapterFactory.java:810) > ... 12 more > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346)