0

Please, before pointing that this is duplicate of What is a NullPointerException, and how do I fix it?, read the post to the end, as this is prepared as adviced on the mentioned site!

I moved my app from Wildfly 8 to Wildfly 10 and to my suprise I've got NullPointerException in place of where in my opinion it shouldn't be.

Piece of code of AdmUserCrud.java - update() method:

119: inst.setRoles(roles);
120: if (inst.getAllowIp()!=null && inst.getAllowIp().equals(""))
121:  inst.setAllowIp(null);

Error:

Caused by: java.lang.NullPointerException
        at com.i4u.qla.action.setting.AdmUserCrud.update(AdmUserCrud.java:120)
        at com.i4u.qla.action.setting.AdmUserCrud$Proxy$_$$_WeldSubclass.update$$super(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jboss.weld.interceptor.proxy.TerminalAroundInvokeInvocationContext.proceedInternal(TerminalAroundInvokeInvocationContext.java:49)
        at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:77)
        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:117)
        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:53)
        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:76)
        at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:47)
        at sun.reflect.GeneratedMethodAccessor125.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:74)
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeAroundInvoke(InterceptorMethodHandler.java:84)
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:72)
        at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:56)
        at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:79)
        at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:68)
        at com.i4u.qla.action.setting.AdmUserCrud$Proxy$_$$_WeldSubclass.update(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at javax.el.ELUtil.invokeMethod(ELUtil.java:300)
        at javax.el.BeanELResolver.invoke(BeanELResolver.java:415)
        at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
        at com.sun.el.parser.AstValue.invoke(AstValue.java:285)
        at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
        at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
        at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
        at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
        at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
        ... 59 more

Line 119 (and not visible lines above) assures that inst object is not null. So why line 120 raises the NullPointer error? I'm really confused.

Community
  • 1
  • 1
robson
  • 1,623
  • 8
  • 28
  • 43
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – JFPicard Jan 17 '17 at 18:05
  • @JFPicard - I wrote the problem following tips on site you pointed – robson Jan 17 '17 at 18:26

1 Answers1

1

It might be the case that the inst.getAllowIp() returns different results on subsequent calls. So when it does first part of the if:

(inst.getAllowIp()!=null && ...

it might result some value, and a while later...

.. && inst.getAllowIp().equals("") )

might already be a null.

One way to prevent that (although it might not be exactly what you need) is to get the value only once, e.g. something along the lines of

inst.setRoles(roles);
String currentIp = inst.getAllowIp();
if (currentIp!=null && currentIp.equals("")) 
  ...

In general I don't think it has any direct connection to Wildfly version changing.

Grzegorz Oledzki
  • 23,614
  • 16
  • 68
  • 106
  • That's it. Although I don't understand why my value is changing. getAllowIp() is a simple getter which doesn't have any hidden logic. The only explanation that comes to my mind is Java version upgrade - maybe something has changed - Wildfly 10.1 requires Java 8. Thank you anyway :-) – robson Feb 09 '17 at 21:45