Avoid NullPointerExceptions from LoadContexts.cleanup(ResultSet)

Description

Hi,

in a couple of loadtests that we do we noticed that a substantial amount of hidden NPEs is thrown from Hibernate when using Stream returns and LoadContext.cleanup(ResultSet) is called internally, but the actual collectionLoadContext was already removed. This seems to happen when the cleanup was already done by CollectionLoadContext.endCollectionLoad.

The actual runtime isn't affected because AbstractScrollableResults.close() ignores the exception and doesn't propagate it. Raising exceptions comes with an overhead, though.

A PR with defensive handling of null inside LoadContext.cleanup(ResultSet) will follow.

Cheers,
Christoph

Environment

None

Assignee

Unassigned

Reporter

Christoph Dreis

backPortable

Backport?