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

Fixed a number of warnings #286

Merged
merged 3 commits into from
Nov 4, 2015
Merged

Conversation

oscargus
Copy link
Contributor

@oscargus oscargus commented Nov 2, 2015

Got rid of a number of warnings:

  • <>
  • static methods
  • commented empty blocks
  • general clean up

@@ -160,7 +160,7 @@ public void start(String[] args) {
openWindow(loaded);
}

private void setupLogHandlerForErrorConsole() {
private static void setupLogHandlerForErrorConsole() {
Copy link
Member

Choose a reason for hiding this comment

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

Why do you turn this static? It is not called from a static context.

@lenhard
Copy link
Member

lenhard commented Nov 3, 2015

I find this PR very valuable (we need such improvements). The only thing I am unsure about is turning various methods static (see above). Can you explain the rationale behind this? Why is static needed here?

@koppor
Copy link
Member

koppor commented Nov 3, 2015

The static conversion is because Eclipse warns if methods could be made static. On the one hand, we could add @suppresswarning if we are sure that Eclipse is wrong. On the other hand, we could just turn off the static warning. I don't have strong a opinion about that. I currently lean towards making methods static if possible to show that they don't access instance variables.

@oscargus
Copy link
Contributor Author

oscargus commented Nov 3, 2015 via email

@lenhard
Copy link
Member

lenhard commented Nov 3, 2015

I tend to disagree with the warning and would prefer non-static versions. The problem with the use of static is that it leads to a higher degree of coupling within the system. Every user of a static method uses the very same instance (that is, the class) and this transitively couples two users although there might be no need for it.

Don't get me wrong, the code works with both versions. Especially if the class is instantiated only once, as is the case in the above line I commented at, there is no difference execution-wise. It is merely a "design smell". I have the opinion that a design with a lot of use of static is "worse" than a more object-oriented design. If we consistently favor static over non-static, we end up with a purely imperative program, which means we are propably using the wrong programming language.

@JabRef/developers This is about a coding guideline and concerns everyone. So what are the opinions of the remaining people? Should we consistently fix the Eclipse warning regarding the use of static, or should we turn it off?

@oscargus
Copy link
Contributor Author

oscargus commented Nov 3, 2015

OK, I've read up and see the point. I'd say that maybe one should go through all the static methods and remove the static keyword and add warning removal in case it does not make sense to access the method in a static way.

For reference: I've done this in the earlier cleanups as well, so it may be better to go over it once and for all (although I can of course start by changing these ones back).

@matthiasgeiger
Copy link
Member

I agree with @lenhard - we should try to reduce the usage of static methods and not introduce new ones.
Quick rule of thumb:

Static is sensible in Utility classes which provide independent small methods, e.g, getIntValue(...). Static should be avoided in more complex "logic classes" - even if only static or no members are accessed.

Objections? @lenhard

I don't like @suppressWarnings annotations - so would either turn off this warning completely - or just ignore those warnings "manually", i.e., think about it and decide whether the usage is okay or not.

@lenhard
Copy link
Member

lenhard commented Nov 3, 2015

@matthiasgeiger full ack 👍

@koppor
Copy link
Member

koppor commented Nov 3, 2015

Could you review eb44184 and efce4ec (unrelated, but I think, it's important, too)

@lenhard
Copy link
Member

lenhard commented Nov 3, 2015

@koppor Looks got to me. I imported the project into Eclipse and am not getting the warning at the above position. I also agree with you on the usage of "this": it should not be mandatory.

However, I found another Eclipse warning, we should be aware of here. In the following line

new FocusRequester(((BasePanel) JabRef.jrf.tabbedPane.getComponentAt(0)).mainTable);

Eclipse warns that The allocated object is never used. The warning is a false positive. FocusRequester starts itself in a separate Thread in its constructor (which is unsafe publication and a potential bug, but that is a different issue) and it does not matter that it is not used at this position. I don't think we should ignore the unused warning, but we should not blindly delete every variable for which it occurs. Instead, we should add a @SuppressWarnings("unused"), if it is a false positive.

@oscargus
Copy link
Contributor Author

oscargus commented Nov 4, 2015

I have removed the statics introduced in this PR.

@oscargus
Copy link
Contributor Author

oscargus commented Nov 4, 2015

Rebased on current master so it should be possible to merge this (unless any other issues arise).

@oscargus oscargus mentioned this pull request Nov 4, 2015
* @param child
* Sorts the entry list using the values of the string entry variable sort.key$. It has no arguments.
*
* @param
Copy link
Member

Choose a reason for hiding this comment

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

@param should be removed here completely

@matthiasgeiger
Copy link
Member

Huh.... requires quite some time to scroll through all your changes 😉

As you can see above I had a few remarks.

Apart from those: Good job! Should be ready to merge (which should be easy after your rebasing - bonus kudos for this 🏆)

@oscargus
Copy link
Contributor Author

oscargus commented Nov 4, 2015

Thanks for the review! Should be good to go now.

matthiasgeiger added a commit that referenced this pull request Nov 4, 2015
@matthiasgeiger matthiasgeiger merged commit 988ffff into JabRef:master Nov 4, 2015
@oscargus oscargus deleted the warningremoval3 branch November 4, 2015 21:35
aryanVanaik pushed a commit to aryanVanaik/jabref that referenced this pull request Oct 27, 2023
@InAnYan InAnYan mentioned this pull request Mar 22, 2024
6 tasks
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.

4 participants