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

Fix checkstyle violations #2624

Merged
merged 3 commits into from
Nov 27, 2016
Merged

Conversation

Tropid
Copy link
Contributor

@Tropid Tropid commented Nov 25, 2016

Contains

Fixes all checkstyle error violations.

How to test

Run ./gradlew checkstyleMain or open the project in eclipse with the checkstyle plugin active (should also work with any other IDE).

Critical parts

  • I added an implementation for equals() in ChunkImpl because the hashCode() method is overwritten
  • I renamed some constants in /engine/src/main/java/org/terasology/rendering/openvrprovider/ControllerListener.java
  • I changed a lambda expression to an anonymous class instantiation as the checkstyle tool seems to get confused by variable declarations inside lambdas (in my defense, this was a big lambda function so in my opinion it's not really worse to use an anonymous class) -> /engine/src/main/java/org/terasology/logic/console/commandSystem/ConsoleCommand.java

@GooeyHub
Copy link
Member

Can one of the admins please verify this patch?


ChunkImpl that = (ChunkImpl) obj;

return Objects.equal(this.chunkPos, that.chunkPos);
Copy link
Member

Choose a reason for hiding this comment

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

This one makes me wonder. Under regular circumstances you would indeed expect two chunks at the same location to equal each other. But are we setting ourselves up for potential bugs here?

Two cases come to mind:

  • We have a known issue about duplicate chunks being loaded (Crash in multiplayer - chunk loading / rendering null issue, maybe related to dupe chunk loading [$50] #2590) - could this somehow affect that? If somehow a dupe chunk loads but a system interaction changes only one of them. I don't know if dupe chunks at all persist beyond a timing issue or something causing two load requests to be issued.
  • In the future could somebody come up with a way where we could have two valid chunks in the same location? Imagine something related to dimensions somehow, either completely separate worlds (why anybody would compare two such chunks I don't know .. but MC does relate the position of Nether chunks vs Overworld chunks so who knows) or in-place chunks where a weird bizarro world shows two different players different chunks. Or phasing maybe (like bits of world with progression locked to individual players)

Perhaps we should add in hashing some additional stuff from each chunk and compare those as well? I don't know how frequently this method is likely used (or really a parent implementation)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of another dimension, we surely should hash another value and also compare another value. But you are correct this could have unforeseen changes.

The important part of the Object contract here should be:

hashCode() must always return the same code for two objects which are equal according to the equals() implementation.

This is true here. I'll adjust the implementation so that equals calls only super and provide a comment why the super equals() implementation is correct in this case.

public static float triggerThreshold = .25f;
int LEFT_CONTROLLER = 0;
int RIGHT_CONTROLLER = 1;
int EAXIS_TRIGGER = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Any chance these names are made to match naming in another place, like the VR provider itself?

@indianajohn - ping! :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, I'd suggest adding the SuppressionWarnings module to the checkstyle.xml and add a @SuppressWarnings annotation to the class.

@Cervator
Copy link
Member

@Tropid Hi there and thanks! Looking good, noted two things I'm curious about :-)

@GooeyHub: ok to test

@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

We don't know the consequences of changing the equals() implementation,
therefore we just test for instance equality like before.
Fixes all error violations in the Core project and also refactors some
inner classes inside the debug.BenchmarkScreen to standalone classes.
@GooeyHub
Copy link
Member

Hooray Jenkins reported success with all tests good!

@Cervator Cervator merged commit 10b7ec0 into MovingBlocks:develop Nov 27, 2016
Cervator added a commit that referenced this pull request Nov 27, 2016
@Cervator Cervator added this to the Alpha 6 milestone Nov 27, 2016
@Cervator
Copy link
Member

Thanks! Merged and added to credits :-)

@Cervator Cervator added the Category: Build/CI Requests, Issues and Changes targeting gradle, groovy, Jenkins, etc. label Nov 27, 2016
@Tropid
Copy link
Contributor Author

Tropid commented Nov 27, 2016

Have you noticed I also fixed the violations in the core project? I missed that at first and don't want to sneak in any unnoticed changes.

@Cervator
Copy link
Member

I looked over all the affected files just in case, but am not too worried exactly where they are. It's all in the same repository after all :-)

@Tropid Tropid deleted the checkstyle_violations branch March 5, 2017 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Build/CI Requests, Issues and Changes targeting gradle, groovy, Jenkins, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants