Skip to content

Fixed a number of warnings#286

Merged
matthiasgeiger merged 3 commits into
JabRef:masterfrom
oscargus:warningremoval3
Nov 4, 2015
Merged

Fixed a number of warnings#286
matthiasgeiger merged 3 commits into
JabRef:masterfrom
oscargus:warningremoval3

Conversation

@oscargus

@oscargus oscargus commented Nov 2, 2015

Copy link
Copy Markdown
Contributor

Got rid of a number of warnings:

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

Comment thread src/main/java/net/sf/jabref/JabRef.java Outdated

Copy link
Copy Markdown
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

lenhard commented Nov 3, 2015

Copy link
Copy Markdown
Member

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

koppor commented Nov 3, 2015

Copy link
Copy Markdown
Member

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

oscargus commented Nov 3, 2015 via email

Copy link
Copy Markdown
Contributor Author

@lenhard

lenhard commented Nov 3, 2015

Copy link
Copy Markdown
Member

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

oscargus commented Nov 3, 2015

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

lenhard commented Nov 3, 2015

Copy link
Copy Markdown
Member

@matthiasgeiger full ack 👍

@koppor

koppor commented Nov 3, 2015

Copy link
Copy Markdown
Member

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

@lenhard

lenhard commented Nov 3, 2015

Copy link
Copy Markdown
Member

@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

oscargus commented Nov 4, 2015

Copy link
Copy Markdown
Contributor Author

I have removed the statics introduced in this PR.

@oscargus

oscargus commented Nov 4, 2015

Copy link
Copy Markdown
Contributor Author

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
Comment thread src/main/java/net/sf/jabref/bst/VM.java Outdated

Copy link
Copy Markdown
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
Copy Markdown
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

oscargus commented Nov 4, 2015

Copy link
Copy Markdown
Contributor Author

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
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