Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

impossible Java method call behavior

Tags:

java

I have a little bit of code in a class running in Java 1.7.0_17 and Jboss 4.2.3GA under windows. The code does this:

Date newNextDate = inBetween(currentDate, nextDate, start);
print("newNextDate=" + newNextDate);

The inbetween does a fairly simply comparison:

private Date inBetween(Date start, Date end, Date test) {
    ...
    Date contains = t.contains(test) ? test : end;
    print("returning contains=" + contains);
    return contains;
}

The exact implementation contains is not relevant IMHO, because in the end results in a java.util.Date being assigned to the contains variable. The output on stdout is:

16:44:56,153 INFO returning contains=Tue Apr 30 23:59:59 CEST 2013
16:44:56,153 INFO newNextDate=null

And this where where the mystery begins: 1. just prior to the return statement the contains variable has a value 2. after returning the collecting variable is null

How in the world is this possible?

  • Yes, we've checked if exactly this inbetween method is called, otherwise it would not have printed the output.
  • No, there is no instance variable with the same name. But even if, there is nothing happening in between.
  • No, we cannot debug the process, because it only occurs on our production servers and is not reproducable on development.

The strangest thing is, it only occurs here, nowhere else in the 1.000.000 lines of code.

like image 853
tbeernot Avatar asked Jun 05 '13 15:06

tbeernot


1 Answers

Maybe you have overloaded your inBetween and that gets called:

private Date inBetween(long start, Date end, Date test) {
     Date result = null;
     inBetween(new Date(start), end, test);
     return result;
}

Or something similarly typical. A catch ... return null.

The only other technical way would be to have an AOP interceptor doing a wrong caching (memoization?) or so. Unlikely.

like image 117
Joop Eggen Avatar answered Nov 10 '22 14:11

Joop Eggen