2

我们使用了一种第 3 方库的方法(我不能命名它,因为它是一个商业解决方案),它的方法看起来或多或少像这样(很多参数):

numerix.setPrice(Instrument instrument,YieldCurve yc,TradeDate date,Currency c,...)

我 100% 确定我传递的每个参数都是非空的。然而我在方法中得到了一个 NullPointerException 。

怎么可能?

另外我在堆栈跟踪中没有行号,所以我该如何调试它?

4

4 回答 4

3

您的某个参数的成员可能为 null,而 setPrice 方法正在尝试使用它。

例如,Currency 类可能有一个format成员。c.format 可能是您的空指针。检查参数的每个成员。

于 2010-01-27T17:53:21.957 回答
2

他们的代码有很多方法可以在没有您帮助的情况下取消引用空指针。

他们可能会使用您提供的值对数组进行索引,并得出一个空指针。

如果你没有源代码,也没有支持,你唯一的办法是用javap命令反编译并使用调试器,它将引导你完成字节码。

于 2010-01-27T17:53:57.027 回答
1

想到的一个明显的可能性是 numerix 为空。

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.

于 2010-01-27T18:40:34.207 回答
0
  • numerix 对象是否处理状态?也许你必须初始化它。
  • 它是否访问外部资源、静态资源等?
  • 如果您没有源代码,请使用 jd-gui 反编译器检查该方法,看看它是否可能出错。
于 2010-01-27T17:55:55.160 回答