Skip to content

[java] PreserveStackTrace not handling Throwable.addSuppressed(...) #2134

@lars-sh

Description

@lars-sh

Affects PMD Version: 6.19.0

Rule: PreserveStackTrace

Description: The below code generates a false-positive PreserveStackTrace error while the outer exception really is preserved as part of the inner exception using addSuppressed.

This is really a rare case and I'm fine with suppressing it for now, but wanted to let you know about it and maybe this report even helps someone.

Code Sample demonstrating the issue:

try {
	return ...;
} catch (IOException outerException) {
	try {
		return ...;
	} catch (IOException innerException) {
		innerException.addSuppressed(outerException);
		throw new UncheckedIOException(innerException);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions