K
K
Kulikov Alexander2016-09-26 09:16:04
Java
Kulikov Alexander, 2016-09-26 09:16:04

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

3 answer(s)
O
Oleg Tsilyurik, 2016-09-26
@Olej

Is it possible that this is a rare JVM bug?

Almost out of the question.
Maybe it's a bug in your code... and not that rare. ;-)

P
parkito, 2016-09-26
@parkito

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.

M
Mikhail Osher, 2016-09-26
@miraage

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 question

Ask a Question

731 491 924 answers to any question