Skip to content
This repository has been archived by the owner on Sep 17, 2020. It is now read-only.

FP: Possible null dereference #24

Open
ben-manes opened this issue Nov 6, 2016 · 0 comments
Open

FP: Possible null dereference #24

ben-manes opened this issue Nov 6, 2016 · 0 comments

Comments

@ben-manes
Copy link

Possible null dereference in CaffeineSpec.parseDuration().
The expression value.length() may fail with NullPointerException as value
can be null at this location.

static long parseDuration(String key, String value) {
  requireArgument(value != null && !value.isEmpty(), "value of key %s omitted", key);
  return parseLong(key, value.substring(0, value.length() - 1));
}

where requireArgument is defined as,

static void requireArgument(boolean expression, String template, Object... args) {
  if (!expression) {
    throw new IllegalArgumentException(String.format(template, args));
  }
}

Resulting in a null check prior to value.length() so that it will never throw a NPE.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant