Java printer: a static interface method called from an implementing class prints unqualified
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Java
- Stars
- 1
- Forks
- 1
- Avg merge
- 1h 34m
- Merged PRs (30d)
- 7
Getting set up
- No Dockerfile or Docker Compose file
- Has a 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 CodeLaser/maddi
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CodeLaser/maddi#166 · 2 comments ·
Maintainers usually reply within 1 day
-
build/ci good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
front-end:rust
Difficulty 5/5 Over a week Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
CodeLaser/maddi#165 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
protobuf
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
FasterXML/jackson-dataformats-binary#874 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
-
[Bug][Connector-V2][JDBC] Turkish locale bypasses the SQL set-operator and complex-clause guards, rewriting the user's queryPossibly taken @SEPURI-SAI-KRISHNA claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 3 days
-
[Bug report] Lance REST catalog-level DropNamespace drops non-lakehouse catalogsPossibly taken @nevzheng claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Maintainers usually reply within 1 day
-
[BUG] jackson3 JacksonJsonpMapper(ObjectMapper) fails to deserialize `_source` with "Trailing token" errorPossibly taken @junyeokk claimed this today. Openbug untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/opensearch-java#2236 ·
Maintainers usually reply within 1 day