Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Java printer: outer.new Inner() prints as outer.new X.Inner()

Closed Beginner friendly
#107 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
compilers

Research direction

Start with the round trip the report describes: parse the snippet in the issue, then call JavaInspector.print2 with Formatter2Impl. The bug is in how the printer writes the class name of a qualified instance creation (outer.new Inner(...)), so find where that expression is formatted and where the type name is qualified. Done when the snippet prints as outer.new Inner(1) and this.new Inner(2), and the output re-parses.

Written by the indexing model from the issue text.

Description

bug

Problem

A qualified inner-class instance creation, outer.new Inner(...), is printed with the class name qualified as well. That isn't valid Java: javac reports '(' expected.

public class X {
    class Inner { final int v; Inner(int v) { this.v = v; } }
    static Inner make(X outer) { return outer.new Inner(1); }
    Inner makeThis() { return this.new Inner(2); }
}

prints as

static X.Inner make(X outer) { return outer.new X.Inner(1); }
X.Inner makeThis() { return this.new X.Inner(2); }

Expected

After outer.new, the class is named by its simple name, relative to the outer instance's type: outer.new Inner(1), this.new Inner(2).

Seen on

A round trip (parse, then JavaInspector.print2 with Formatter2Impl) on maddi 0.9.5-alpha.5. On real code:

  • picocli: OFF.new CommandLine.Help.Ansi.Text(0) and this.new CommandLine.Help.Ansi.Text(...) in CommandLine.java. The whole file fails to re-parse, which is almost all of picocli.
  • javaparser: ParserConfiguration.this.new ParserConfiguration.UnicodeEscapeProcessor().
Dominant language
Java
Stars
1
Forks
1
Avg merge
1h 58m
Merged PRs (30d)
5

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from CodeLaser/maddi

All issues in CodeLaser/maddi

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.