Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Incorrect analyzer feedback: finalSalary should not be forced to use a ternary when Math.min is clearer

Aperta
#298 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

Individua la regola dell’Analyzer che emette il feedback citato sul ternario e riproducilo con l’esercizio descritto nell’issue. Determina come la regola valuta l’uso dei ternari in salaryMultiplier, bonusMultiplier e finalSalary; il lavoro è completato quando non raccomanda più un ternario meno chiaro quando il cap Math.min esistente è appropriato, con copertura di regressione per il feedback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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:

  1. detect that ternaries are used elsewhere and suppress this suggestion, or
  2. 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.

Lingua principale
Java
Stelle
13
Fork
27
Merge medio
1g 11h
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di exercism/java-analyzer

Tutte le issue di exercism/java-analyzer

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.