简体   繁体   English

不可能的Java方法调用行为

[英]impossible Java method call behavior

I have a little bit of code in a class running in Java 1.7.0_17 and Jboss 4.2.3GA under windows. 我在Windows下以Java 1.7.0_17和Jboss 4.2.3GA运行的类中有一些代码。 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. 确切的实现contains与IMHO不相关,因为最终导致将java.util.Date分配给contains变量。 The output on stdout is: stdout的输出为:

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 这就是谜团开始的地方:1.在return语句之前,contains变量具有值2.在返回collection变量之后为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. 是的,我们已经检查了是否恰好调用了这个inweenween方法,否则它将不会输出输出。
  • 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. 最奇怪的是,它仅在此处发生,在1.000.000行的代码中没有其他地方。

Maybe you have overloaded your inBetween and that gets called: 也许您已经超载了inBetween并被称为:

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 . 一个catch ... return null

The only other technical way would be to have an AOP interceptor doing a wrong caching (memoization?) or so. 唯一的其他技术方法是让AOP拦截器执行错误的缓存(内存化)。 Unlikely. 不太可能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM