Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Soundness: a local variable with a constant's name shadows the constant (Format.JPG read as local JPG)

Offen Anfängerfreundlich
#321 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 2 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java
Bereich
testing

Rechercherichtung

Beginne in RefinementTypeChecker.visitCtFieldRead, das im Issue angegeben ist, und reproduziere den Namenskonflikt mit dem bereitgestellten Java-Beispiel. Prüfe, wie die Kontextsuche zwischen einer lokalen Variable und dem gelesenen Feld unterscheidet; das Issue beschreibt einen möglichen Fix und berichtet, dass alle 347 Tests bestehen. Erledigt ist es, wenn der Reproducer einen Refinement-Fehler bei onlyPng(g) meldet und die Testsuite weiterhin besteht.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug

Description

A field read of a constant such as Format.JPG is resolved to a local variable with the same simple name (JPG), if one is in scope, instead of the constant. The refinement of the local is then used, so real violations are accepted.

Minimal reproducer

import liquidjava.specification.Refinement;

public class Repro {
    enum Format { JPG, PNG }

    static void onlyPng(@Refinement("_ == Format.PNG") Format f) {}

    public static void main(String[] args) {
        Format JPG = Format.PNG;       // a local that happens to share the constant's name
        Format g = Format.JPG;         // the enum constant JPG, not the local
        onlyPng(g);                    // expected error: g is JPG
    }
}

Expected

A refinement error at onlyPng(g): g holds Format.JPG.

Actual

Correct! Passed Verification.

Removing the line Format JPG = Format.PNG; gives the expected error (g == JPG is not a subtype of g == Format.PNG), so the name clash is what hides it.

Reproduced on main at fbfb4e23.

Where

RefinementTypeChecker.visitCtFieldRead: its first branch looks the field up by simple name in the context (where the local lives) without checking that the variable found is the field being read. A candidate fix (about 5 lines, found during the review of #319) only uses the context variable when it really is that field, and otherwise falls through; it keeps all 347 tests passing.

Context

Found by the adversarial review of #319 (fix for #302): with #319 the same clash inside an if condition (if (f == Format.JPG)) turns a former crash into an accepted violation, so this should be fixed before or with #319.

Vorherrschende Sprache
Java
Sterne
67
Forks
36
Ø Merge
3 T. 16 Std.
Gemergte PRs (30 T.)
9

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus liquid-java/liquidjava

Alle Issues in liquid-java/liquidjava

Ähnliche Issues

Weitere Issues zu Java

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.