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

Clean Up: Add final modifier to private fields #739

Merged
merged 2 commits into from
Sep 13, 2023
Merged

Conversation

jukzi
Copy link
Contributor

@jukzi jukzi commented Sep 11, 2023

No description provided.

@github-actions
Copy link

github-actions bot commented Sep 11, 2023

Test Results

     246 files  ±0       246 suites  ±0   59m 57s ⏱️ - 4m 30s
  3 299 tests ±0    3 271 ✔️  - 1  24 💤 ±0  0 ±0  4 🔥 +1 
10 194 runs  ±0  10 118 ✔️  - 1  72 💤 ±0  0 ±0  4 🔥 +1 

For more details on these errors, see this check.

Results for commit ed65987. ± Comparison against base commit d880fec.

♻️ This comment has been updated with latest results.

@vogella
Copy link
Contributor

vogella commented Sep 12, 2023

I personally see no value in adding more words (final) to the code and in the past we have actually reduced the usage of final. WDYT @HannesWell?

@iloveeclipse
Copy link
Member

I personally see no value in adding more words (final) to the code

Final fields are good, because they avoid possibly improper field initialization at runtime.

and in the past we have actually reduced the usage of final.

Not sure who is "we" and why removing final would be desired?

@merks
Copy link
Contributor

merks commented Sep 12, 2023

I think final fields make it more clear that one doesn't not intend subsequent assignment. With implicit final variables in newer Javas, the use of final in the body of a method is kind of noisy...

@@ -24,7 +24,7 @@
*/
public class CollapseAllAction extends Action {

private TreeViewer fViewer;
private final TreeViewer fViewer;
Copy link
Contributor

Choose a reason for hiding this comment

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

does this compile? AFAIK, this produces unitialized final field error.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's assigned in the constructor, so yes it compiles without errors:

image

@jukzi
Copy link
Contributor Author

jukzi commented Sep 12, 2023

"final" on local variables is bad boiler plate and should be removed. But on fields it is mandatory for proper multi threading. I am tired to solve single missing finals, so i just added all missing. May be it adds some keywords to structures that are not used concurrently but it's to much work for me to figure out where it is needed and where it could be skipped.
see
https://stackoverflow.com/questions/27254152/what-exactly-does-the-final-keyword-guarantee-regarding-concurrency
https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5

@merks
Copy link
Contributor

merks commented Sep 12, 2023

Not to hijack this topic...

I wonder if there is anything that finds pointless initialization of fields to their default value, e.g.,

image

This actually generates byte code to do that initialization so is actually worse than pointless...

@vogella
Copy link
Contributor

vogella commented Sep 12, 2023

"final" on local variables is bad boiler plate and should be removed. But on fields it is mandatory for proper multi threading. I am tired to solve single missing finals, so i just added all missing. May be it adds some keywords to structures that are not used concurrently but it's to much work for me to figure out where it is needed and where it could be skipped. see https://stackoverflow.com/questions/27254152/what-exactly-does-the-final-keyword-guarantee-regarding-concurrency https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5

Thanks for clarification, change is fine for me in this case.

@jukzi
Copy link
Contributor Author

jukzi commented Sep 12, 2023

I wonder if there is anything that finds pointless initialization of fields to their default value, e.g.,

ask for a refactoring in jdt

@iloveeclipse
Copy link
Member

I wonder if there is anything that finds pointless initialization of fields to their default value, e.g.,

The compiler knows that and could emit a warning.

@jukzi jukzi force-pushed the final branch 3 times, most recently from 54d7a0e to c682848 Compare September 12, 2023 12:48
@HannesWell
Copy link
Member

I personally see no value in adding more words (final) to the code and in the past we have actually reduced the usage of final. WDYT @HannesWell?

I have the same opinion as the others for the mentioned reasons. Additionally it also makes the code easier to follow because one can be sure that the field's reference is not changed as a side-effect of any method call.

@jukzi
Copy link
Contributor Author

jukzi commented Sep 12, 2023

15:05:27 [ERROR] Failed to execute goal org.eclipse.tycho.extras:tycho-p2-extras-plugin:4.0.2:compare-version-with-baselines (compare-attached-artifacts-with-release) on project org.eclipse.pde.unittest.junit: Only qualifier changed for (org.eclipse.pde.unittest.junit.feature.jar/1.0.500.v20230912-1247). Expected to have bigger x.y.z than what is available in baseline (1.0.500.v20230728-0611) -> [Help 1]

@jukzi
Copy link
Contributor Author

jukzi commented Sep 12, 2023

15:57:01 [API ERROR] File MANIFEST.MF at line 6: The service version is increased unnecessarily since either the major or minor or service version is already increased (location: /home/jenkins/agent/workspace/eclipse.pde_PR-739/ui/org.eclipse.pde.unittest.junit/META-INF/MANIFEST.MF)

@jukzi
Copy link
Contributor Author

jukzi commented Sep 12, 2023

I need help with the version bump here: org.eclipse.pde.unittest.junit - if i increase i get an error, if i do not increase i get an another error :(

@jukzi
Copy link
Contributor Author

jukzi commented Sep 12, 2023

15:05:27 [ERROR] Failed to execute goal org.eclipse.tycho.extras:tycho-p2-extras-plugin:4.0.2:compare-version-with-baselines (compare-attached-artifacts-with-release) on project org.eclipse.pde.unittest.junit: Only qualifier changed for

i guess that error message is wrong and it should say project org.eclipse.pde.unittest.junit-feature

@jukzi
Copy link
Contributor Author

jukzi commented Sep 13, 2023

ignoring unrelated BundleMergeSplitTests #261

@jukzi jukzi merged commit c6a2477 into eclipse-pde:master Sep 13, 2023
11 of 14 checks passed
@jukzi jukzi deleted the final branch September 13, 2023 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants