Whole file

terryyin/lizard

The author described this change as fix(java): do not report control structures as methods. It counts as a record because the checks below fail on the code as it stood at 0b97a9ae8 and pass on a3ed8d6c6, with nothing else changed between the two runs.

Fix saved2026-08-08
Sharing licenceMIT · LICENSE.txt
Change size+10 0

What the code was meant to do, written into the code itself as a save note

fix(java): do not report control structures as methods

The change

1515 'void', 'boolean', 'byte', 'char', 'short', 'int', 'long', 'float', 'double', 'var',
1616 })
1717 _JAVA_BRACE_COUNT = {'{': 1, '}': -1}
18+# JLS 3.9: reserved keywords can never be a method name, so "keyword (...) { ... }"
19+# is a statement, not a declaration. Without this, a control structure written at
20+# a level where no class body state is active (e.g. a static initializer block at
21+# the top of the token stream) is reported as a method. See issue #312.
22+_JAVA_STATEMENT_KEYWORDS = frozenset({
23+ 'if', 'else', 'for', 'while', 'do', 'switch', 'catch', 'try', 'finally',
24+ 'synchronized', 'return', 'throw', 'assert', 'break', 'continue', 'instanceof',
25+})
1826
1927
2028 def _java_record_begins_type_declaration(last_token, after_unqualified_annotation):
138146 self._state = self._state_decorator
139147 return
140148 if self._try_start_a_class(token, use_after_annotation):
149+ return
150+ if token in _JAVA_STATEMENT_KEYWORDS:
141151 return
142152 if not self.in_record_constructor: # Only process as potential function if not in record constructor
143153 super(JavaStates, self)._state_global(token)

The check that tells the two apart

failpass·test/test_languages/testJava.py::TestJava::test_issue_312_control_structures_are_not_methods
failpass·test/test_languages/testJava.py::TestJava::test_issue_312_structure_in_static_block

Check file test/test_languages/testJava.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before it0b97a9ae8e77b8d559e7ef187ad4b4e3ef02924f
Broken version dated2026-06-15
Modulelizard_languages.java
Units changedJavaStates
Fingerprint122821113ad051a5
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in terryyin/lizard