Java Code Smells: 7 Patterns to Catch in Code Review (With Fixes) (video)

A practical list of Java code smells — empty catch blocks, long methods, large classes, too many parameters, deep nesting, hardcoded credentials, and missing logging — with before-and-after examples.

Read the full article

Transcript

Java Code Smells: 7 Patterns to Catch in Code Review (With Fixes). Here's the short version.

A code smell is not a bug — it is a pattern that makes bugs more likely and changes more expensive. Java codebases tend to accumulate the same handful of smells, especially in long-lived enterprise services.

Empty catch blocks. An empty catch swallows the exception and lets the caller believe the operation succeeded. In Java it often appears around checked exceptions that a developer wanted to “make go away”.

Here's the problem in code: the failure disappears.

And here's the fix: log with context, then decide.

Long methods. Methods past roughly 60 lines usually do more than one thing. Extract each step into a well-named private method so the top-level method reads like a summary.

Want to find these issues in your own code? Connect your GitHub repository to CodeInspector. You'll get findings with the file, line, severity, and a recommended fix, plus HTML and PDF reports for your team. Start free at codeinspector.app.

More videos

All videos