Skip to content

Refactor: improve code quality by addressing code smells - #560

Open
naim0-0 wants to merge 1 commit into
zalando:mainfrom
naim0-0:refactor/code-smell-fixes
Open

Refactor: improve code quality by addressing code smells#560
naim0-0 wants to merge 1 commit into
zalando:mainfrom
naim0-0:refactor/code-smell-fixes

Conversation

@naim0-0

@naim0-0 naim0-0 commented Jul 4, 2026

Copy link
Copy Markdown

Summary

This pull request improves code quality through several non-behavioral refactorings.

Changes

  • Improved documentation in DefaultProblem
  • Simplified Problem.toString() implementation
  • Improved documentation for ThrowableProblem
  • Replaced magic strings with named constants in ProblemBuilder
  • Simplified JUnit stack trace detection logic
  • Declared lookup map as final in StatusTypeAdapter

Verification

  • Project builds successfully.
  • All existing tests pass.
  • No public APIs or runtime behavior were changed.

@naim0-0
naim0-0 requested a review from fatroom as a code owner July 4, 2026 08:00

@prashantpiyush1111 prashantpiyush1111 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the refactoring work. Overall, the changes are clear and improve readability in several places.

However, I noticed one potential behavioral change in Problem.toString(): changing problem.getType().toString() to string concatenation changes the behavior when getType() returns null (NPE vs. "null"). Since the PR is intended to be non-behavioral, I recommend preserving the existing behavior here.

Also, the new @SuppressWarnings("unchecked") in ThrowableProblem#getCause() appears unnecessary because this is not an unchecked generic cast. It would be cleaner to remove it.

Apart from these points, the refactoring looks reasonable.

.filter(Objects::nonNull)
.collect(joining(", "));

return problem.getType() + "{" + body + "}";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This changes the behavior when problem.getType() is null: the previous implementation called toString() explicitly and would throw a NullPointerException, while string concatenation converts null to the literal "null". Since this PR is described as non-behavioral, could we preserve the existing problem.getType().toString() behavior here?

* @return the cause of this problem, or {@code null} if no cause exists
*/
@Override
@SuppressWarnings("unchecked")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is @SuppressWarnings("unchecked") necessary here? The cast is from Throwable to ThrowableProblem and does not appear to be an unchecked generic cast, so I think this suppression can be removed.

statusCode,
problem.getTitle(),
problem.getDetail(),
instancePart

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we add or update a regression test for the refactored toString() implementation, particularly around nullable fields, to demonstrate that this refactoring preserves the existing behavior?


private static final Set<String> RESERVED_PROPERTIES =
Collections.unmodifiableSet(
new LinkedHashSet<>(java.util.Arrays.asList(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this set is only used for contains() and is already private static final, is the LinkedHashSet/unmodifiableSet combination necessary here? A simpler immutable set construction would make this refactor easier to read.

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.

2 participants