Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Null进入数组_Java_Multithreading - Fatal编程技术网

Java Null进入数组

Java Null进入数组,java,multithreading,Java,Multithreading,我想知道null是如何进入这个memcached对象数组的 Object[] value = (Object[]) SuperCache.getInstance() .get(key); Object data = cacheStore.getValue(); Object[] newValue; if (data != null) { if (value == null || value.length <= 0) {

我想知道null是如何进入这个memcached对象数组的

Object[] value = (Object[]) SuperCache.getInstance()
                    .get(key);
Object data = cacheStore.getValue();
Object[] newValue;
    if (data != null) {
        if (value == null || value.length <= 0) {
            newValue = new Object[1];
            newValue[0] = data;
            log.info("CacheThread : no value found for k"
                    + key + ", adding a new value now v"
                    + data);
        } else {
            newValue = new Object[value.length + 1];
            newValue[0] = data;
            System.arraycopy(value, 0, newValue, 1,
                    value.length);
            for (int i = 0; i < newValue.length; i++) {
----->          if (newValue[i] == null)
                    log.error("null getting into cache here, for key "
                            + key);
            }
        }
        cacheData(key, newValue, cacheStore.getExpiry());
        log.info("CacheThread " + this.toString()
            + " Lenght of Array" + newValue.length
            + "for k" + key + "v" + newValue);
    }
Object[]value=(Object[])超级缓存.getInstance()
.取得(钥匙);
对象数据=cacheStore.getValue();
对象[]新值;
如果(数据!=null){
if(value==null | | value.length if(newValue[i]==null)
log.error(“此处进入缓存的值为null,用于密钥”
+键);
}
}
cacheData(key,newValue,cacheStore.getExpiry());
log.info(“CacheThread”+this.toString()
+“数组长度”+newValue.length
+“对于k”+键+v”+新值);
}
在上面所指的那行,我正在检查newValue数组是否有空值。但是因为您注意到我是通过迭代构建数组的


为什么我在这里得到一个空值?

数组
可以包含
空值
值。您不会在任何地方对它们进行检查

只需在第二行中打印它们即可验证这一点:

for (int i = 0; i < value.length; i++) {
      if (value[i] == null)
            log.error("null getting into cache here, at index" + i);
for(int i=0;i

这可能就是您所需要的。

您正在将一个长度数组
值。长度
复制到一个长度数组
值。长度+1
。您不应该期望一个项目保持空值吗?(您案例中的第一个项目是因为您开始从
destPos=1
)请参阅:我已经调试过它,没有发现这个问题。因此,这里的问题。为什么要投票?如果我做了更改,所有的数据元素将被新的<代码>数据< /代码>取代,我将丢失现有数据。好的提示,现有的数据已经无效,请考虑批准。
else {
            newValue = new Object[value.length + 1];
            newValue[0] = data; // this part is assigning only index 0 to an object, you're looping to < newValue.length index
            System.arraycopy(value, 0, newValue, 1,
                    value.length);
            for (int i = 0; i < newValue.length; i++) {
                if (newValue[i] == null) // when i = 1 onwards, it will be null as they are not assigned yet
                    log.error("null getting into cache here, for key "
                            + key);
            }
        }
else {
            newValue = new Object[value.length + 1];
            System.arraycopy(value, 0, newValue, 1,
                    value.length);
            for (int i = 0; i < newValue.length; i++) {
               newValue[i] = data;
               if (newValue[i] == null)
                    log.error("null getting into cache here, for key "
                            + key);
            }