Skip to content

Static Code Task : Addition

DarkSetis edited this page Apr 25, 2017 · 8 revisions

András Jánoky:

The findBugs output

Bad Practices

The first two "Problems with implementation of equals()" is because they used the @Override to override the default compareTo method, but they did not override the equals() method, so the two can give back conflicting information, as compareTo should only return 0 if equals() returns true. If you override the one but not the other there Might be conflicts which can cause problems.

Comparator doesn't implement Serializable class, but in the given context, there isn't a TreeMap or anything like that that loses it's serializability.

Internationalization

They used a default encoding, which calls a method that performs a byte to String conversion, and assumes tha the default platform encoding is suitable. The call :

BufferedReader factoryReader = new BufferedReader(new InputStreamReader(url.openStream()));

Is basically 100% percent equals to the one that is on Oracle's website "https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html"

URL oracle = new URL("http://www.oracle.com/"); BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream()));

Dodgy Code: Code contains hard coded reference to an absolute pathname. The pathnames are put as global variables, in Public static final. public static final String ROOT_DIR = "/home/tredmond/Shared/ontologies/prompt/chebi"; This might be a problem as the separator for different Operating Systems might differ / vs \ so this is not a good solution.

Performance:

There is a huge performance problem with a Mapt Iterator, that iterates through a keySet and checks if the entry of the given key is someting. This step could be avoided if they iterated through an entrySet instead of a keySet.

Clone this wiki locally