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

Java printer: a nested type prints by simple name when the unit imports another type of that name

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start at the Java printer and the importComputer call shown in the issue, then trace how it decides whether a nested type can print by its simple name. Reproduce the case with the two Builder types and confirm the printed source resolves to the wrong one. Done when the nested type remains unambiguous in printed output and the example can be reparsed successfully.

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

描述

bug

A nested type of an imported type, written Outer.Impl.Builder, prints by its simple name Builder when the unit also imports another type named Builder. The printed unit then means the imported type.

package a.c;
public class Builder { }
package a.d;
public class Outer {
  public static class Impl {
    public static class Builder { public Builder set(int i) { return this; } }
  }
}
package a.b;
import a.c.Builder;
import a.d.Outer;
public class X {
    Builder own;
    Object make() {
        return new Outer.Impl.Builder().set(0);
    }
}

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

public class X { Builder own; Object make() { return new Builder().set(0); } }

so new Builder() is a.c.Builder, which has no set. It looks as if the printer takes the simple name as visible because some type of that simple name is imported, without checking it is the same type. (#114 was the converse: a nested type qualified by an outer name the unit had taken.)

Found re-parsing printed sources of jenkins core: hudson.model.Build, Project, hudson.Functions and jenkins.model.Jenkins import hudson.tasks.Builder and use another nested Builder; all four units are dropped (the re-parse then fails with "Unexpected javac type in convert: 'recovery'"). Jenkins alone held 8 of the idiom sites lost in that run.

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 摘要。