aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2012-06-21 10:42:07 (EDT)
committerOleg Besedin2012-06-21 10:42:07 (EDT)
commit1dcf65511f4dd7a466922b8e39d1824b72977ed1 (patch)
tree0bbc85698ab10574fde5001bb56056e80cef98df
parentdb1818d0bab27a1bf2d9b4c5c0186169f9cf3f9b (diff)
downloadeclipse.platform.runtime-1dcf65511f4dd7a466922b8e39d1824b72977ed1.zip
eclipse.platform.runtime-1dcf65511f4dd7a466922b8e39d1824b72977ed1.tar.gz
eclipse.platform.runtime-1dcf65511f4dd7a466922b8e39d1824b72977ed1.tar.bz2
Bug 377343 - NullPointerException in the C/C++ Projects View on eclipsepwebster/start_421
startup
-rw-r--r--bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/InjectorImpl.java10
-rw-r--r--tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java32
2 files changed, 38 insertions, 4 deletions
diff --git a/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/InjectorImpl.java b/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/InjectorImpl.java
index 7eac2f4..1d943a3 100644
--- a/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/InjectorImpl.java
+++ b/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/InjectorImpl.java
@@ -271,10 +271,11 @@ public class InjectorImpl implements IInjector {
}
private Object internalMake(Class<?> clazz, PrimaryObjectSupplier objectSupplier, PrimaryObjectSupplier tempSupplier) {
- if (classesBeingCreated.contains(clazz))
- throw new InjectionException("Recursive reference trying to create class " + clazz.getName()); //$NON-NLS-1$
+ if (shouldDebug && classesBeingCreated.contains(clazz))
+ LogHelper.logWarning("Possible recursive reference trying to create class \"" + clazz.getName() + "\".", null); //$NON-NLS-1$ //$NON-NLS-2$
try {
- classesBeingCreated.add(clazz);
+ if (shouldDebug)
+ classesBeingCreated.add(clazz);
boolean isSingleton = clazz.isAnnotationPresent(Singleton.class);
if (isSingleton) {
@@ -326,7 +327,8 @@ public class InjectorImpl implements IInjector {
}
throw new InjectionException("Could not find satisfiable constructor in " + clazz.getName()); //$NON-NLS-1$
} finally {
- classesBeingCreated.remove(clazz);
+ if (shouldDebug)
+ classesBeingCreated.remove(clazz);
}
}
diff --git a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java
index dfbf57f..bca24c2 100644
--- a/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java
+++ b/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/manual/InjectionErrorReportingTest.java
@@ -21,6 +21,7 @@ import org.eclipse.e4.core.contexts.ContextInjectionFactory;
import org.eclipse.e4.core.contexts.EclipseContextFactory;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.InjectionException;
+import org.eclipse.e4.core.di.annotations.Creatable;
/**
* Manual test to observe error reporting. The JUnits in this
@@ -111,6 +112,12 @@ public class InjectionErrorReportingTest extends TestCase {
}
}
+ @Creatable
+ static class InjectedRecursive {
+ @Inject
+ public InjectedRecursive field;
+ }
+
/**
* Shows the error message for an unresolved method argument
*/
@@ -234,6 +241,31 @@ public class InjectionErrorReportingTest extends TestCase {
assertTrue(exception);
}
+ /**
+ * Manual test to check error message for recursive object creation
+ */
+ public void testRecursionError() {
+ IEclipseContext context = EclipseContextFactory.create();
+ boolean exception = false;
+ try {
+ ContextInjectionFactory.make(InjectedRecursive.class, context);
+ } catch (InjectionException e) {
+ basicLog(e);
+ exception = true;
+ }
+ assertTrue(exception);
+
+ context.set(InjectedRecursive.class, new InjectedRecursive());
+ exception = false;
+ try {
+ ContextInjectionFactory.make(InjectedRecursive.class, context);
+ } catch (InjectionException e) {
+ basicLog(e);
+ exception = true;
+ }
+ assertFalse(exception);
+ }
+
private void basicLog(InjectionException e) {
e.printStackTrace(System.out);
}