Answer the question
In order to leave comments, you need to log in
How, after converting long to Long, could I get null?
I have some method whose parameter is Long.
And this method is called with a long (primitive) parameter. Judging by the logs, in this method I get null at the input. Common sense is indignant: the situation is not possible, but the fact remains. Everything that can be excluded is excluded. Can't repeat.
Is it possible that this is a rare JVM bug? Or what other options might there be?
It is difficult to give a code example, but formally:
//EJB1
final long foo = data.getLongValue();
ejb2.bar(foo);
//EJB2
bar(Long x) {
entityManager.find(SomeClass.class, x);
//java.lang.IllegalArgumentException: id to load is required for loading
//что означает только что x == null
//ВАЖНО после перезапуска веб сервера ошибка пропадает
}
Answer the question
In order to leave comments, you need to log in
Is it possible that this is a rare JVM bug?
The modern JVM is very good. In 99.999999%, the error in the application must be looked for in your code. If you have a multi-threaded application, then there is nothing surprising in the fact that the bug cannot be repeated.
In general, it's best to avoid classes when you can use primitives.
Exception: generics.
foo(Long num) {
// omitted
}
long x = 10;
foo(x); // говорите, вот так null?
foo(new Long(x)); // а если так?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question