NullPointerException but no null parameters passed to the function
There is a method of a 3rd party library we use (I can't name it because it's a commercial solution) which has a method which looks more or less like this (lots and lots params):
numerix.setPrice(Instrument instrument,YieldCurve yc,Tr开发者_如何学GoadeDate date,Currency c,...)
I am 100% sure that each param I pass is non-null. Yet I get a NullPointerException inside the method.
How can it be?
Also I have no line number in the stack trace so how can I debug it?
It's possible that a member of one of your parameters is null, and the setPrice method is trying to use that.
For example, the Currency class might have a format
member. c.format could be your null pointer. Check each member of the parameters.
There are many ways their code could dereference a null pointer with no help from you.
They might index an array with a value you supply and come up with a null pointer.
If you don't have source, and you don't have support, your only recourse is to decompile with the javap
command and use a debugger which will step you through the byte code.
An obvious possibility that comes to mind is that numerix is null.
The thing to do is check the stack trace on the exception and see what line is throwing it. Are you getting the exception on the call, or is it coming from inside the function? If the latter, you're back to Aaron's answer: one of the parameters could be an object with a member that is null. Or maybe somewhere in the processing inside, the function is creating a null object because of a bug of its own or invalid inputs. (Failure to check the inputs is arguably a bug in any case, but whatever.)
Do you have the source code? If so, you can home in on the line that the stack trace identifies. If not, you're working blind, and the best you can do is carefully check out all your parameters.
- Does the numerix object handle state? Maybe you have to initialize it then.
- Does it access external resources, static resources, etc?
- If you don't have source, use the jd-gui decompiler to inspect the method to see if it can possibly go wrong.
精彩评论