Details
-
Type: Bug
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: 2.8
-
Fix Version/s: 2.9
-
Component/s: PicoContainer (Java)
-
Labels:None
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
Description
The following code throws a NullPointerException
Unable to find source-code formatter for language: test. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
public static class TestStartable implements org.picocontainer.Startable { @Override public void start() { // empty } @Override public void stop() { // empty } } @Test public void testIsStartedShouldNotThrowOnNonStartedComponent() { DefaultPicoContainer cont = new DefaultPicoContainer(); cont.as(CACHE).addComponent(TestStartable.class); ComponentAdapter<?> adapter = cont.getComponentAdapter(TestStartable.class); Cached cached = adapter.findAdapterOfType(Cached.class); // this line throws - instead of returning false assertFalse(cached.isStarted()); }
This is caused by the instance not being cached yet (instanceReference.get() == null), and hence the .started member cannot be accessed.
Suggest to fix by changing RealComponentLifecycle<T>.isStarted() to (this is the 'patch')
Unable to find source-code formatter for language: fixed realcomponentlifecycle. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
public boolean isStarted() { // add this guardInstRef() line guardInstRef(); return instanceReference.get().started; }
thx Mark.