-
Notifications
You must be signed in to change notification settings - Fork 340
java answers
Yegor Bugayenko edited this page Aug 17, 2023
·
20 revisions
This a list of problems in the Java file, in order of importance (the biggest problems are on top):
- It's not really a class, but a collection of utility procedures (see)
- It is doing too many things at the same time: saving, loading, filtering
- There is an obvious code duplication in
getContent*
methods - The
getContent()
will corrupt the content if there are Unicode symbols in the file - It is mutable, getters and setters should be removed and a constructor introduced
- It doesn't
implement
any interfaces - Names like
get/set
would sound better thanget/save
- The class is not thread-safe, despite the promise in the Javadoc
- Exception swallowing is an obvious mistake
- Unicode filtering is done wrong, will break the content instead of filtering it
- Variable names are very short and non-informative
- String concatenation is very ineffective in terms of performance
- It's better to use
Files.readAllBytes()
instead of manual reading/writing -
while ((data = i.read()) > 0)
is a bad style, should bewhile (true)
- Input and output streams are not buffered
- One-byte reading is ineffective, we should read to the memory buffer
- Both streams are not closed after use
- All non-modifiable variables should be
final
-
i += 1
is not the best method of variable increment, should be++i
-
file
is not prepended withthis.
If you miss the first three problems, we won't work with you.