Skip to content

AbstractEntityInformation.isNew() method violates declared API behavior #2567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
superbrown opened this issue Mar 1, 2022 · 1 comment
Closed
Assignees
Labels
type: documentation A documentation update

Comments

@superbrown
Copy link

superbrown commented Mar 1, 2022

The javadoc for the class reads as such:

/**
 * Base class for implementations of {@link EntityInformation}. Considers an entity to be new whenever
 * {@link #getId(Object)} returns {@literal null}.

However, the implementation of the isNew(T entity) method also considers the object new if the object's id is set to 0:

	public boolean isNew(T entity) {

		ID id = getId(entity);
		Class<ID> idType = getIdType();

		if (!idType.isPrimitive()) {
			return id == null;
		}

		if (id instanceof Number) {
			return ((Number) id).longValue() == 0L;
		}

		throw new IllegalArgumentException(String.format("Unsupported primitive id type %s!", idType));
	}

This has surfaced as a problem with a project I'm working on because the project's design relied upon 0 being considered a valid ID.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 1, 2022
@mp911de mp911de added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 2, 2022
@mp911de mp911de self-assigned this Mar 2, 2022
@mp911de
Copy link
Member

mp911de commented Mar 2, 2022

Thanks for bringing this up. Indeed the implementation has changed while we missed updating the documentation.

mp911de added a commit that referenced this issue Mar 2, 2022
Align documentation with the code behavior as the behavior was changed but the documentation was not updated with the previous change.

Closes #2567
mp911de added a commit that referenced this issue Mar 2, 2022
Align documentation with the code behavior as the behavior was changed but the documentation was not updated with the previous change.

Closes #2567
mp911de added a commit that referenced this issue Mar 2, 2022
Align documentation with the code behavior as the behavior was changed but the documentation was not updated with the previous change.

Closes #2567
@mp911de mp911de closed this as completed in 19f4fd1 Mar 2, 2022
@mp911de mp911de added this to the 2.5.10 (2021.0.10) milestone Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants