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

Java printer: in a local class, a line comment before a field swallows the field

Closed
#108 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start from the round trip described in the issue: parse a local class with a line comment before a field, then run JavaInspector.print2 with Formatter2Impl. Find where the printer emits the comment and the following field for class bodies, and check why local classes take a different path from member classes, which print correctly. Done when the local-class example prints the comment on its own line and the field stays intact and compilable, and the member-class output is unchanged.

Written by the indexing model from the issue text.

Description

bug

Problem

In a local class (a class declared inside a method body), a line comment before a field is printed on the same line as the field. The field becomes part of the comment, and the class no longer compiles: every use of the field fails with "cannot find symbol".

int local(List<int[]> in) {
    class Entry {
        public final int a;

        // TODO: a comment before a field
        public final List<int[]> b;

        Entry(int a, List<int[]> b) { this.a = a; this.b = new ArrayList<>(b); }
    }
    return new Entry(1, in).a;
}

prints as

class Entry {
    final int a;
    // TODO: a comment before a field final List<int []> b;
    Entry(int a, List<int []> b) { this.a = a; this.b = new ArrayList<>(b); }
}

The same class declared as a nested (member) class prints correctly, with the comment on its own line.

Expected

A line comment always ends its line, wherever it is.

Seen on

A round trip (parse, then JavaInspector.print2 with Formatter2Impl) on maddi 0.9.5-alpha.5. On real code: fernflower's FinallyProcessor, whose local class BlockStackEntry has // TODO: correct handling (merging) of multiple paths before the field lstStoreVars. Possibly related to #49 (comment positions), but there's no moved code here.

Dominant language
Java
Stars
1
Forks
1
Avg merge
2h 51m
Merged PRs (30d)
3

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.