[jboss-as7-dev] If you see a NPE in your unit tests during an InitialContext reference...

Andrew Lee Rubinger andrew.rubinger at redhat.com
Wed Aug 17 09:02:59 EDT 2011


This is due to:

https://issues.jboss.org/browse/ARQ-458
https://github.com/arquillian/arquillian-core/commit/a7def997135c3535f8fbbf55878a6e47bd47afe5

We can't execute @BeforeClass in-container, so injection it is (which is 
nicer anyway, ain't it? :) )

And as Scott correctly notes, @ArquillianResource provides the facility.

Related but a bit tangential, when injecting stuff like EJBs I do:

@EJB(mappedName="globalJndiName")

...rather than lookups.

S,
ALR

On 08/16/2011 11:54 PM, Scott Marlow wrote:
> Perhaps your on a branch and synced up with AS7 master as I just did.
> Or your on master and have some @Ignore tests that you occasionally use
> (and also just synced with the latest master commits).
>
> It looks like this was already fixed in all of the active unit tests
> (thank you!).  For disabled tests or on your branches, you might need to
> add "@ArquillianResource" around your InitialContext variables.  You can
> probably also delete your assignment to the InitialContext variable as well.
>
> Good code:
>
>       @ArquillianResource InitialContext iniCtx;
>
>
> This code will get a NPE when it uses iniCtx:
>
>       private static InitialContext iniCtx;
>
>       @BeforeClass
>       public static void beforeClass() throws NamingException {
>           iniCtx = new InitialContext();
>       }
>
> Hope this helps.
>
> Scott
> _______________________________________________
> jboss-as7-dev mailing list
> jboss-as7-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-as7-dev

-- 
Andrew Lee Rubinger
Senior Software Engineer
JBoss by Red Hat
Twitter: @ALRubinger
http://about.me/alrubinger


More information about the jboss-as7-dev mailing list