Skip to content

NullPointerException in RepeatTemplate#doHandle() when unwrapIfRethrown() returns null if logging in DEBUG #1123

Closed
@spring-projects-issues

Description

@spring-projects-issues

Cyril Dejonghe opened BATCH-2479 and commented

I'm facing a case where unwrapIfRethrown() returns null (initial exception with no cause) :

/**
 * Unwraps the throwable if it has been wrapped by
 * {@link #rethrow(Throwable)}.
 */
	private static Throwable unwrapIfRethrown(Throwable throwable) {
		if (throwable instanceof RepeatException) {
			return throwable.getCause();
		}
		else {
			return throwable;
		}
	}

This causes doHandle() to fail :

	private void doHandle(Throwable throwable, RepeatContext context, Collection<Throwable> deferred) {
		// An exception alone is not sufficient grounds for not continuing
		Throwable unwrappedThrowable = unwrapIfRethrown(throwable);
		try {
			...
			if (logger.isDebugEnabled()) {
				logger.debug("Handling exception: " + throwable.getClass().getName() + ", caused by: " + unwrappedThrowable.getClass().getName() + ": " + unwrappedThrowable.getMessage());
			}
			exceptionHandler.handleException(context, unwrappedThrowable);

		} catch (Throwable handled) {
			deferred.add(handled);
		}
	}

The cause seem pretty clear : calling unwrappedThrowable.getClass().getName() + ": " + unwrappedThrowable.getMessage() on a null object ...


Affects: 3.0.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions