Skip to content

Fix NPE when closing an unopened JpaPagingItemReader - #5541

Open
harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:GH-5539
Open

harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:GH-5539

Conversation

@harrisleesh

Copy link
Copy Markdown

entityManager is only assigned in doOpen() and is @Nullable, but doClose() called entityManager.close() with no null check (the nullness warning was suppressed via @SuppressWarnings("DataFlowIssue")). Spring calls close() on every singleton ItemReader bean at context shutdown regardless of whether its step ran, causing an NPE wrapped as ItemStreamException for readers that were never opened.

This guards the EntityManager cleanup with a null check while still performing the superclass cleanup, mirroring the fix applied to JpaCursorItemReader in #5486 / #5489, and adds a regression test.

Fixes #5539

entityManager is only assigned in doOpen() and is @nullable, but
doClose() called entityManager.close() with no null check, with the
nullness warning suppressed via @SuppressWarnings("DataFlowIssue").
Spring calls close() on every singleton ItemReader bean at context
shutdown regardless of whether its step ran, causing an NPE wrapped
as ItemStreamException for readers that were never opened.

Guard the EntityManager cleanup with a null check while still
performing the superclass cleanup, mirroring the fix applied to
JpaCursorItemReader in spring-projectsGH-5486.

Fixes spring-projects#5539

Signed-off-by: seonghun lee <harrisleesh@gmail.com>
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

Successfully merging this pull request may close these issues.

NullPointerException when closing an unopened JpaPagingItemReader

1 participant