Skip to content
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

chore(EntityPool): workaround "unchecked generics array creation" for getEntitiesWith #5052

Merged
merged 1 commit into from
Jun 26, 2022

Conversation

keturn
Copy link
Member

@keturn keturn commented Jun 21, 2022

Java generic types are a mess, especially where varargs are involved. We can't use @SafeVarargs on interface methods because there is no way to know the implementations of the interface are safe.

In this case, in practice, there are few (if any) callers that pass more than two values.
By adding methods that explicitly take one and two values, we can present an interface the compiler doesn't need to complain about at every call site.

How to Test

  • find any caller of entityManager.getEntitiesWith(SomeComponent.class)
  • notice unhappy compiler and IDE messages about "unchecked generics array creation for varargs parameter"
  • apply PR
  • notice lack of unhappy compiler and IDE messages

@keturn keturn added Size: S Small effort likely only affecting a single area and requiring little to no research Type: Chore Request for or implementation of maintenance changes Type: Refactoring Request for or implementation of pure and automatic refactorings, e.g. renaming, to improve clarity labels Jun 21, 2022
@keturn
Copy link
Member Author

keturn commented Jun 21, 2022

I guess the alternative would be seeing if we can globally disable varargs-related warnings? I've read the FAQ but I still feel like this should be a check on the implementation, not at every call site.

As long as methods aren't writing to the varargs array, it doesn't seem like something to worry about. Am I missing something?

Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests out fine 👍

@jdrueckert jdrueckert merged commit 2b01ea7 into develop Jun 26, 2022
@jdrueckert jdrueckert deleted the chore/entityPoolVarargs branch June 26, 2022 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: S Small effort likely only affecting a single area and requiring little to no research Type: Chore Request for or implementation of maintenance changes Type: Refactoring Request for or implementation of pure and automatic refactorings, e.g. renaming, to improve clarity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants