From 1dcf65511f4dd7a466922b8e39d1824b72977ed1 Mon Sep 17 00:00:00 2001 From: Oleg Besedin Date: Thu, 21 Jun 2012 10:42:07 -0400 Subject: Bug 377343 - NullPointerException in the C/C++ Projects View on eclipse startup --- .../eclipse/e4/core/internal/di/InjectorImpl.java | 10 ++++--- .../tests/manual/InjectionErrorReportingTest.java | 32 ++++++++++++++++++++++ 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 7eac2f46e..1d943a36d 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 dfbf57fc0..bca24c2e8 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); } -- cgit v1.2.3