Replace access to null field with a call to method that doesn't throw any exception.
1.1 --- a/context/src/main/java/net/java/html/BrwsrCtx.java Wed Jun 24 22:42:35 2015 +0200
1.2 +++ b/context/src/main/java/net/java/html/BrwsrCtx.java Wed Jun 24 23:51:08 2015 +0200
1.3 @@ -70,6 +70,8 @@
1.4 private BrwsrCtx(CtxImpl impl) {
1.5 this.impl = impl;
1.6 }
1.7 + /** currently {@link #execute(java.lang.Runnable) activated context} */
1.8 + private static final ThreadLocal<BrwsrCtx> CURRENT = new ThreadLocal<BrwsrCtx>();
1.9 static {
1.10 new CtxAccssr() {
1.11 @Override
1.12 @@ -89,8 +91,6 @@
1.13 */
1.14 public static final BrwsrCtx EMPTY = Contexts.newBuilder().build();
1.15
1.16 - /** currently {@link #execute(java.lang.Runnable) activated context} */
1.17 - private static final ThreadLocal<BrwsrCtx> CURRENT = new ThreadLocal<BrwsrCtx>();
1.18
1.19 /** Seeks for the default context that is associated with the requesting
1.20 * class. If no suitable context is found, a warning message is
1.21 @@ -101,6 +101,9 @@
1.22 * @return appropriate context for the request
1.23 */
1.24 public static BrwsrCtx findDefault(Class<?> requestor) {
1.25 + if (requestor == CtxAccssr.class) {
1.26 + return EMPTY;
1.27 + }
1.28 BrwsrCtx brwsr = CURRENT.get();
1.29 if (brwsr != null) {
1.30 return brwsr;
2.1 --- a/context/src/main/java/org/netbeans/html/context/impl/CtxAccssr.java Wed Jun 24 22:42:35 2015 +0200
2.2 +++ b/context/src/main/java/org/netbeans/html/context/impl/CtxAccssr.java Wed Jun 24 23:51:08 2015 +0200
2.3 @@ -54,11 +54,7 @@
2.4 private static CtxAccssr DEFAULT;
2.5 static {
2.6 // run initializers
2.7 - try {
2.8 - BrwsrCtx.EMPTY.getClass();
2.9 - } catch (NullPointerException ex) {
2.10 - // ignore
2.11 - }
2.12 + BrwsrCtx.findDefault(CtxAccssr.class);
2.13 }
2.14
2.15 protected CtxAccssr() {