brianfrankcooper / YCSB

Yahoo! Cloud Serving Benchmark
Apache License 2.0
4.9k stars 2.22k forks source link

A Risk of Null Dereference #1618

Open zhaoyangyingmu opened 2 years ago

zhaoyangyingmu commented 2 years ago

Hello, I found an NullPointerException Risk at line 151 of site.ycsb.BasicTSDB.

@Override
  public Status update(String table, String key, Map<String, ByteIterator> values) {
    // ... 
    if (verbose) {
    // ...
      if (values != null) {// check values here
        final TreeMap<String, ByteIterator> tree = new TreeMap<String, ByteIterator>(values);
        // ...
    }
    if (count) {
      if (!verbose) {
        isFloat = ((NumericByteIterator) values.get(valueKey)).isFloatingPoint(); // values could be null here
       // suggested: isFloat = values == null? false:((NumericByteIterator) values.get(valueKey)).isFloatingPoint();
      }
      // ...
    }
    return Status.OK;
  }

The variable values could be null and has two usages, but only the first usage is guarded by a null check, the second isn't. Hope this suggestion is helpful!