tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: some NPE protections
Date Wed, 02 Dec 2015 18:31:38 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 04294bfde -> f9f73a49b


some NPE protections


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/f9f73a49
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/f9f73a49
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/f9f73a49

Branch: refs/heads/master
Commit: f9f73a49bc51e56613da9e64c85b79502fcb5b2a
Parents: 04294bf
Author: Romain Manni-Bucau <rmannibu@gmail.com>
Authored: Wed Dec 2 19:31:31 2015 +0100
Committer: Romain Manni-Bucau <rmannibu@gmail.com>
Committed: Wed Dec 2 19:31:31 2015 +0100

----------------------------------------------------------------------
 .../openejb/testing/ApplicationComposers.java   | 35 +++++++++++++++-----
 .../apache/openejb/bval/BeanValidationTest.java |  4 +++
 2 files changed, 30 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f73a49/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
index bc5fefd..4f54482 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
@@ -373,8 +373,7 @@ public class ApplicationComposers {
 
     @SuppressWarnings("unchecked")
     public void before(final Object inputTestInstance) throws Exception {
-        // we hacked testInstance while we were not aware of it, now we can solve it
-        testClassFinders.put(inputTestInstance, testClassFinders.remove(this));
+        fixFakeClassFinder(inputTestInstance);
 
         startContainer(inputTestInstance);
 
@@ -385,12 +384,7 @@ public class ApplicationComposers {
     }
 
     public void deployApp(final Object inputTestInstance) throws Exception {
-        // test injections
-        ClassFinder testClassFinder = testClassFinders.remove(inputTestInstance);
-        if (testClassFinder == null) {
-            testClassFinders.put(inputTestInstance, testClassFinders.remove(this));
-            testClassFinder = testClassFinders.remove(inputTestInstance);
-        }
+        final ClassFinder testClassFinder = fixFakeClassFinder(inputTestInstance);
 
         final ClassLoader loader = testClass.getClassLoader();
         AppModule appModule = new AppModule(loader, testClass.getSimpleName());
@@ -773,6 +767,29 @@ public class ApplicationComposers {
         testClassFinders.put(this, testClassFinder);
     }
 
+    private ClassFinder fixFakeClassFinder(final Object inputTestInstance) {
+        // test injections, we faked the instance before having it so ensuring we use the
right finder
+        ClassFinder testClassFinder = testClassFinders.get(inputTestInstance);
+        if (testClassFinder == null) {
+            final ApplicationComposers self = this;
+            final ClassFinder remove = testClassFinders.remove(self);
+            if (remove != null) {
+                testClassFinders.put(inputTestInstance, remove);
+                testClassFinder = remove;
+                afterRunnables.add(new Runnable() { // reset state for next test
+                    @Override
+                    public void run() {
+                        final ClassFinder classFinder = testClassFinders.remove(inputTestInstance);
+                        if (classFinder != null) {
+                            testClassFinders.put(self, classFinder);
+                        }
+                    }
+                });
+            }
+        }
+        return testClassFinder;
+    }
+
     private boolean isCdi(final boolean cdi, final Class<?>[] cdiInterceptors,
                           final Class<?>[] cdiAlternatives, final Class<?>[]
cdiStereotypes,
                           final Class<?>[] cdiDecorators) {
@@ -1264,7 +1281,7 @@ public class ApplicationComposers {
     public void startContainer(final Object instance) throws Exception {
         originalProperties = (Properties) System.getProperties().clone();
         originalLoader = Thread.currentThread().getContextClassLoader();
-        testClassFinders.remove(this); // see constructor
+        fixFakeClassFinder(instance);
 
         // For the moment we just take the first @Configuration method
         // maybe later we can add something fancy to allow multiple configurations using
a qualifier

http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f73a49/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
index 9ac79d6..4d7136f 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
@@ -23,6 +23,7 @@ import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.apache.openejb.junit.ApplicationComposer;
 import org.apache.openejb.testing.Configuration;
 import org.apache.openejb.testing.Module;
+import org.apache.openejb.testing.SimpleLog;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -51,12 +52,15 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+@SimpleLog
 @RunWith(ApplicationComposer.class)
 public class BeanValidationTest {
     @EJB
     private PersistManager persistManager;
+
     @Resource
     private Validator validator;
+
     @Resource
     private ValidatorFactory validatorFactory;
 


Mime
View raw message