Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache with read-through cache loader throws NPE #119

Closed
chrisstockton opened this issue Sep 1, 2016 · 10 comments
Closed

Cache with read-through cache loader throws NPE #119

chrisstockton opened this issue Sep 1, 2016 · 10 comments

Comments

@chrisstockton
Copy link

Whenever a CacheLoader.load() returns a null, the JCacheLoaderAdapter.load() doesn't check that the value is not null before wrapping it in an Expirable which doesn't allow nulls.

Adding return value == null ? null : new Expirable<>(value, expireTimeMS()); on line 81 seems to fix the failing test.

https://github.com/ben-manes/caffeine/compare/master...chrisstockton:read-through-load-null?expand=1

CacheLoader.loadAll() also has the same problem and is similarly fixable, but hopefully it's not as common to return a null instead of any empty map.

@ben-manes
Copy link
Owner

ben-manes commented Sep 1, 2016

ahh, sorry about that. I relied on the TCK with additional tests based on code coverage and discovered bugs. Unfortunately the TCK turns out to be pretty poor and admittedly I put most of my effort towards Caffeine's core test suite. The adapter is a lot larger than I'd like due to significant differences in designs.

Since there might be other mistakes, can you use a SNAPSHOT? I figure you'll be banging on it a bit over the next few days and we can avoid version noise. If that's okay, then I'd bump the release when you gave the thumbs up.

@chrisstockton
Copy link
Author

Sure, sounds good. It might take a little longer than a few days, "real-work" is getting in the way lately. But I'll be playing with it when I have spare time.

@ben-manes
Copy link
Owner

Thanks! Just let me know when you're moving off either due to lack of time or no more issues found. I think we can delay because JCache has had low adoption, isn't the primary API, and the module has a tiny download rate (253 in July according to Central).

@ben-manes
Copy link
Owner

It seems that loadAll does not define what happens on a null return value. Neither the JavaDoc nor the specification mention it, and none of the other implementations have special handling so they too would NPE. So I'm going to be null averse in my reading and assume it is not allowed.

@ben-manes
Copy link
Owner

Snapshot should be good now that the CI behaves correctly again.

ben-manes added a commit that referenced this issue Sep 1, 2016
This is required by the specification (per JavaDoc) but the TCK does
not validate it, so sadly I failed to handle that case.

To get CI functioning again, moving back to a jdk8-only config. I don't
know why the new config hangs with Guava's tests and think it might be
the distro.

Also fixed the misnamed method for DI factories. I'm going to argue it
doesn't break semvar since JCache is the API and this is an impl hook
no one calls directly.
ben-manes added a commit that referenced this issue Sep 1, 2016
This is required by the specification (per JavaDoc) but the TCK does
not validate it, so sadly I failed to handle that case.

To get CI functioning again, moving back to a jdk8-only config. I don't
know why the new config hangs with Guava's tests and think it might be
the distro.

Also fixed the misnamed method for DI factories. I'm going to argue it
doesn't break semver since JCache is the API and this is an impl hook
no one calls directly.
@chrisstockton
Copy link
Author

I had to take a break for a while there, but I picked this back up a few weeks ago. I've been using the cache loader with read-through from the snapshot in production for about a week now and haven't found any more issues.

@ben-manes
Copy link
Owner

Thanks! Let me sort out #127 and then I'll get you a proper version.

@chrisstockton
Copy link
Author

Does it look like 2.3.4 will be out soon. It's looking like #127 is fixed?

@ben-manes
Copy link
Owner

I'd like to wait until JCTools is released with the fix, in case additional tests are going to be added. But if not then done soon then I'll go ahead regardless and apply the changes, which are non-invasive. Its critical enough that I won't delay it beyond this week and will have a release out over the weekend regardless of JCTools' status.

@ben-manes
Copy link
Owner

Released 2.3.4 with this fix. Thanks for being patient.

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

No branches or pull requests

2 participants