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

Java printer: a static interface method called from an implementing class prints unqualified

Aperta
#168 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

Start by tracing how javaInspector.print2 decides whether a static call can omit its owner qualifier, then inspect the implicit-scope logic for static methods declared on interfaces. Reproduce the issue with the Item and Use.Impl example in the report, including the fully qualified call. Done when printing preserves the interface type and the printed source compiles; the payload names no test file.

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

Descrizione

bug

A call to a static method of an interface prints without its type when the caller's class implements that interface. Static interface methods are not inherited (JLS 8.4.8), so the bare call does not compile.

package proj.v1;
public interface Item {
    static Item from(Object o) { return null; }
    String name();
}
package proj;
import proj.v1.Item;
public class Use {
    public static final class Impl implements Item {
        private final Object delegate;
        public Impl(Object delegate) { this.delegate = delegate; }
        @Override public String name() { return Item.from(delegate).name(); }
    }
}

javaInspector.print2(cu, null, javaInspector.importComputer(Integer.MAX_VALUE, cu.sourceSet())) prints the body as

@Override public String name() { return from(delegate).name(); }

and javac rejects it: cannot find symbol: method from(Object), location: class Impl. The same happens when the source writes the type fully qualified (proj.v1.Item.from(delegate), with a homonym proj.v2.Item imported): the qualifier is dropped all the same.

Found re-parsing printed sources of jenkins core: FileParameterValue.FileItemImpl implements org.apache.commons.fileupload.FileItem calls org.apache.commons.fileupload.FileItem.fromFileUpload2FileItem(delegate), printed as fromFileUpload2FileItem(delegate). The re-parse drops the unit, 42 units in that run (two passes) for this reason.

Probably the "implicit scope" decision for a static call: a static method of a superclass may be called unqualified from a subclass, but a static method of a superinterface may not. Keep the type qualifier when the method's owner is an interface (unless the call is inside that interface itself).

maddi 0.9.5-alpha.36.

Lingua principale
Java
Stelle
1
Fork
1
Merge medio
1h 55m
PR unite (30g)
8

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 CodeLaser/maddi

Tutte le issue di CodeLaser/maddi

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.