Spring-boot: ErrorAttributeOptions.excluding throws IllegalArgumentException if includes is empty

Created on 13 Nov 2020  路  7Comments  路  Source: spring-projects/spring-boot

The excluding method of ErrorAttributeOptions throws an IllegalArgumentException Collection is empty if its includes member field is empty.

Offending Code:

public ErrorAttributeOptions excluding(Include... excludes) {
        EnumSet<Include> updated = EnumSet.copyOf(this.includes);
        updated.removeAll(Arrays.asList(excludes));
        return new ErrorAttributeOptions(Collections.unmodifiableSet(updated));
    }

Notice that the including method handles the empty case correctly:

public ErrorAttributeOptions including(Include... includes) {
        EnumSet<Include> updated = (this.includes.isEmpty()) ? EnumSet.noneOf(Include.class)
                : EnumSet.copyOf(this.includes);
        updated.addAll(Arrays.asList(includes));
        return new ErrorAttributeOptions(Collections.unmodifiableSet(updated));
    }
ideal-for-contribution superseded bug

Most helpful comment

Scott, I suppose you meant @wanderleisouza :smirk:

All 7 comments

@scottfrederick how can I contribute on this? any process details/page link?

@wagnerluis1982 Thanks for the inquiry. There is some useful information in the project contributing guidelines to get started cloning and building the project.

This issue is assigned to the 2.3.x milestone, so you'll want to create your own fork of the project, create a new branch from the 2.3.x branch, commit your changes to the new branch, and submit the pull request against 2.3.x. We'll take care of merging the changes into master from there.

ErrorAttributeOptions doesn't currently have its own tests, but is tested indirectly through DefaultErrorAttributes. It would be good to add a new ErrorAttributesOptionsTests test case to verify this problem and the fix.

Feel free to ask any other questions here.

Scott, I suppose you meant @wanderleisouza :smirk:

@scottfrederick , I've already signed CLA. Can I work on this issue?

@amit-github-personal The issue was first claimed by @wanderleisouza, so let's give them a chance to work on it.

@scottfrederick I just sent a pull request https://github.com/spring-projects/spring-boot/pull/24230 with testes and bug-fix, let me know if everything is correct. Thank you for entire support.

Closing in favour of PR #24230

Was this page helpful?
0 / 5 - 0 ratings