Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Java printer: an Outer.this qualifier on a call is dropped, so the call binds to the inner class's method

未关闭
#175 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

Start by tracing javaInspector.print2 and the Java call-printing logic; the issue gives no source file or test name. Reproduce the example and inspect the printed source to find where the Outer.this qualifier is lost. Done means the qualifier is retained when needed to resolve the call correctly, with a regression test showing the output compiles.

由索引模型根据 Issue 内容生成。

描述

bug

In an anonymous or inner class, a call qualified by the enclosing instance (Outer.this.m(..)) prints as a bare m(..). When the inner class has a method of the same name, the printed call means another method: it no longer compiles or, when the argument types fit, silently calls the wrong one.

package a.b;
import java.util.List;
abstract class X<T> {
    abstract void apply(StringBuilder b, T value);
    final X<List<T>> iterable() {
        return new X<List<T>>() {
            @Override
            void apply(StringBuilder b, List<T> values) {
                if (values == null) return;
                for (T value : values) {
                    X.this.apply(b, value);
                }
            }
        };
    }
}

javaInspector.print2(cu, null, javaInspector.importComputer(4, cu.sourceSet())) prints the loop as

for (T value : values) { apply(b, value); }

which resolves to the anonymous class's own apply(StringBuilder, List<T>), and javac rejects it. The qualifier has to stay when the simple name would find a member of a nearer class, as with an explicit Outer.this the source wrote.

Found re-parsing printed sources of retrofit (ParameterHandler.iterable() and array(): ParameterHandler.this.apply(builder, value)); the unit is dropped. Related to #106 (other qualifiers a call needs).

maddi 0.9.6-alpha.4.

主要语言
Java
星标
1
派生
1
平均合并
1 小时 55 分钟
30 天内合并 PR
8

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

CodeLaser/maddi 的其他 Issue

查看 CodeLaser/maddi 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。