Incorrect analyzer feedback: finalSalary should not be forced to use a ternary when Math.min is clearer
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Locate the analyzer rule that emits the quoted ternary feedback and reproduce it with the exercise described in the issue. Determine how the rule evaluates ternary usage across salaryMultiplier, bonusMultiplier, and finalSalary; done means it no longer recommends a less-clear ternary when the existing Math.min cap is appropriate, with regression coverage for the feedback.
Written by the indexing model from the issue text.
Description
The Java analyzer is giving this automated feedback:
“As the goal of this exercise is to learn about ternary operators consider using them in finalSalary to solve this exercise.”
However, this feedback appears to be incorrect.
My implementation does use ternary operators where appropriate (e.g., in salaryMultiplier and bonusMultiplier), and the logic inside finalSalary does not naturally lend itself to a ternary expression. Instead, the method concludes by applying a salary cap using:
return Math.min(salary, MAX_SALARY);
This is the most idiomatic and intention-revealing way in Java to express “cap a value at a maximum.”
Forcing a ternary here would reduce clarity, for example:
return salary > MAX_SALARY ? MAX_SALARY : salary;
Both statements are functionally equivalent, but the Math.min version:
- more clearly communicates the intent,
- avoids nesting logic inside a ternary,
- reflects common Java practice,
- is simpler to read and maintain,
- aligns with standard clean-code guidelines.
The goal of the exercise is to learn ternary operators, not to artificially apply them in places where they decrease readability or duplicate existing standard library functionality.
Since the solution already uses ternaries appropriately and idiomatically in earlier methods, the analyzer's suggestion is misleading and encourages worse code, not better code. The feedback should either:
- detect that ternaries are used elsewhere and suppress this suggestion, or
- avoid prescribing the use of a ternary in situations where another construct is objectively clearer.
In short, the feedback should guide learners toward idiomatic, expressive Java—not toward unnecessary or forced use of syntax.
If needed, I can provide a minimal code example illustrating the issue.
- Dominant language
- Java
- Stars
- 13
- Forks
- 27
- Avg merge
- 17h 12m
- Merged PRs (30d)
- 3
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from exercism/java-analyzer
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
exercism/java-analyzer#379 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
exercism/java-analyzer#271 · 5 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
exercism/java-analyzer#227 · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
exercism/java-analyzer#218 · 3 comments ·
-
there is no need to use substring in the result method in this code, kindly reviewPossibly taken @manumafe98 claimed this 926 days ago. Openx:size/small
exercism/java-analyzer#176 · 1 comment · 1 assignee ·
All issues in exercism/java-analyzer
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Lincoln-cn/JAiRouter#1473 ·
Maintainers usually reply within 1 day
-
area: ui bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
tetsuji16/microProject#1893 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
liberation-data/fornax4j#325 ·
Maintainers usually reply within 1 day
-
[Bug]: FE and Kinesis extraction pipes render flow starting at the centre and scroll the source arm backwardsPossibly taken @chonkzillaofficial claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
BCCE-team/BuildCraft#85 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 3 days