Skip to content

Commit 65c30f0

Browse files
style: reformat code
Signed-off-by: manticore-projects <andreas@manticore-projects.com>
1 parent 9cfbe68 commit 65c30f0

File tree

5 files changed

+100
-68
lines changed

5 files changed

+100
-68
lines changed

src/main/java/net/sf/jsqlparser/parser/SimpleCharStream.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ public String GetImage() {
328328
if (bufpos >= tokenBegin) {
329329
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
330330
} else {
331-
return new String(buffer, tokenBegin, bufsize - tokenBegin) + new String(buffer, 0, bufpos + 1);
331+
return new String(buffer, tokenBegin, bufsize - tokenBegin)
332+
+ new String(buffer, 0, bufpos + 1);
332333
}
333334
}
334335

@@ -375,10 +376,9 @@ public void adjustBeginLineColumn(int newLine, int newCol) {
375376
int nextColDiff;
376377
int columnDiff = 0;
377378

378-
while (
379-
i < len &&
380-
(int) (buflinecolumn[j = start % bufsize] >>> 32) == (int) (buflinecolumn[k = ++start % bufsize] >>> 32)
381-
) {
379+
while (i < len &&
380+
(int) (buflinecolumn[j = start % bufsize] >>> 32) == (int) (buflinecolumn[k =
381+
++start % bufsize] >>> 32)) {
382382
int colJ = (int) buflinecolumn[j];
383383
int colK = (int) buflinecolumn[k];
384384
nextColDiff = columnDiff + colK - colJ;
@@ -394,7 +394,8 @@ public void adjustBeginLineColumn(int newLine, int newCol) {
394394
int lineJ = (int) (buflinecolumn[j = start % bufsize] >>> 32);
395395
int lineNext = (int) (buflinecolumn[++start % bufsize] >>> 32);
396396
if (lineJ != lineNext) {
397-
buflinecolumn[j] = ((long) (newLine++) << 32) | (buflinecolumn[j] & 0xFFFFFFFFL);
397+
buflinecolumn[j] =
398+
((long) (newLine++) << 32) | (buflinecolumn[j] & 0xFFFFFFFFL);
398399
} else {
399400
buflinecolumn[j] = ((long) newLine << 32) | (buflinecolumn[j] & 0xFFFFFFFFL);
400401
}

src/test/java/net/sf/jsqlparser/parser/BytecodeSizeTest.java

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,40 @@
88
import org.junit.jupiter.api.Test;
99

1010
/**
11-
* Verifies that no method in the generated parser or token manager
12-
* exceeds the JVM's 64KB bytecode limit per method.
11+
* Verifies that no method in the generated parser or token manager exceeds the JVM's 64KB bytecode
12+
* limit per method.
1313
*
14-
* <p>Catches the exact failure scenario:</p>
14+
* <p>
15+
* Catches the exact failure scenario:
16+
* </p>
17+
*
1518
* <pre>
1619
* org.objectweb.asm.MethodTooLargeException:
1720
* Method too large: net/sf/jsqlparser/parser/CCJSqlParserTokenManager.&lt;clinit&gt; ()V
1821
* </pre>
1922
*
20-
* <p>This error occurs when bytecode instrumentation tools (JaCoCo, ASM, ByteBuddy)
21-
* add probes to methods that are already near the 64KB limit. The tests therefore
22-
* enforce a <b>safety margin</b> ({@value #INSTRUMENTATION_HEADROOM_PERCENT}%)
23-
* below the hard JVM limit.</p>
23+
* <p>
24+
* This error occurs when bytecode instrumentation tools (JaCoCo, ASM, ByteBuddy) add probes to
25+
* methods that are already near the 64KB limit. The tests therefore enforce a <b>safety margin</b>
26+
* ({@value #INSTRUMENTATION_HEADROOM_PERCENT}%) below the hard JVM limit.
27+
* </p>
2428
*
25-
* <p>Requires {@link BytecodeSizeVerifier} on the test classpath (same package).</p>
29+
* <p>
30+
* Requires {@link BytecodeSizeVerifier} on the test classpath (same package).
31+
* </p>
2632
*/
2733
public class BytecodeSizeTest {
2834

2935
/**
30-
* Safety margin for bytecode instrumentation (JaCoCo, ASM, etc.).
31-
* Instrumentation typically adds 5-15% overhead; 20% gives comfortable headroom.
32-
* A method at 80% of 64KB (52,428 bytes) will still be safe after instrumentation.
36+
* Safety margin for bytecode instrumentation (JaCoCo, ASM, etc.). Instrumentation typically
37+
* adds 5-15% overhead; 20% gives comfortable headroom. A method at 80% of 64KB (52,428 bytes)
38+
* will still be safe after instrumentation.
3339
*/
3440
private static final int INSTRUMENTATION_HEADROOM_PERCENT = 20;
3541

3642
/**
37-
* Hard fail threshold: 100% minus instrumentation headroom.
38-
* Methods exceeding this will likely break under JaCoCo/ASM instrumentation.
43+
* Hard fail threshold: 100% minus instrumentation headroom. Methods exceeding this will likely
44+
* break under JaCoCo/ASM instrumentation.
3945
*/
4046
private static final int FAIL_PERCENT = 100 - INSTRUMENTATION_HEADROOM_PERCENT;
4147

@@ -48,33 +54,36 @@ public class BytecodeSizeTest {
4854
(int) (BytecodeSizeVerifier.JVM_CODE_LIMIT * (FAIL_PERCENT / 100.0));
4955

5056
/**
51-
* The generated parser/token manager classes to check.
52-
* Inner classes (e.g. CharDataConsts) are checked automatically
53-
* since we scan the entire classes directory.
57+
* The generated parser/token manager classes to check. Inner classes (e.g. CharDataConsts) are
58+
* checked automatically since we scan the entire classes directory.
5459
*/
5560
private static final List<String> CRITICAL_CLASSES = List.of(
5661
"CCJSqlParser",
57-
"CCJSqlParserTokenManager"
58-
);
62+
"CCJSqlParserTokenManager");
5963

6064
// -----------------------------------------------------------------------
6165
// Test: clinit specifically (matches the reported ASM error)
6266
// -----------------------------------------------------------------------
6367

6468
/**
6569
* Reproduces the exact failure scenario:
70+
*
6671
* <pre>
6772
* org.objectweb.asm.MethodTooLargeException:
6873
* Method too large: net/sf/jsqlparser/parser/CCJSqlParserTokenManager.&lt;clinit&gt; ()V
6974
* </pre>
7075
*
71-
* <p>Checks {@code <clinit>} in all parser-related classes (including inner classes
72-
* like {@code CharDataConsts}) against the instrumentation-safe threshold.</p>
76+
* <p>
77+
* Checks {@code <clinit>} in all parser-related classes (including inner classes like
78+
* {@code CharDataConsts}) against the instrumentation-safe threshold.
79+
* </p>
7380
*/
7481
@Test
7582
void clinitMustFitWithinInstrumentationSafeLimit() throws Exception {
7683
List<BytecodeSizeVerifier.Result> results = scanParserClasses();
77-
if (results.isEmpty()) return; // skip if classes not found
84+
if (results.isEmpty()) {
85+
return; // skip if classes not found
86+
}
7887

7988
List<String> failures = new ArrayList<>();
8089

@@ -87,33 +96,37 @@ void clinitMustFitWithinInstrumentationSafeLimit() throws Exception {
8796
if (r.clinitSize > FAIL_THRESHOLD) {
8897
failures.add(String.format(
8998
"%s.<clinit>: %,d bytes (%.1f%%) exceeds %d%% safe limit.\n"
90-
+ " ASM/JaCoCo instrumentation will push this over 64KB.\n"
91-
+ " Fix: move static array initializers to _init() methods.",
99+
+ " ASM/JaCoCo instrumentation will push this over 64KB.\n"
100+
+ " Fix: move static array initializers to _init() methods.",
92101
r.className, r.clinitSize, pct, FAIL_PERCENT));
93102
}
94103
}
95104
}
96105

97106
assertTrue(failures.isEmpty(),
98107
"Static initializer(s) too large for safe instrumentation:\n"
99-
+ String.join("\n", failures));
108+
+ String.join("\n", failures));
100109
}
101110

102111
// -----------------------------------------------------------------------
103112
// Test: all methods (general code-too-large prevention)
104113
// -----------------------------------------------------------------------
105114

106115
/**
107-
* Checks every method in the generated parser and token manager classes
108-
* against the instrumentation-safe threshold.
116+
* Checks every method in the generated parser and token manager classes against the
117+
* instrumentation-safe threshold.
109118
*
110-
* <p>Covers: production methods, jj_3R_* lookahead scanners,
111-
* jj_rescan_token, jj_la1_init_*, and all other generated methods.</p>
119+
* <p>
120+
* Covers: production methods, jj_3R_* lookahead scanners, jj_rescan_token, jj_la1_init_*, and
121+
* all other generated methods.
122+
* </p>
112123
*/
113124
@Test
114125
void allMethodsMustFitWithinInstrumentationSafeLimit() throws Exception {
115126
List<BytecodeSizeVerifier.Result> results = scanParserClasses();
116-
if (results.isEmpty()) return;
127+
if (results.isEmpty()) {
128+
return;
129+
}
117130

118131
List<String> failures = new ArrayList<>();
119132
int totalMethods = 0;
@@ -144,16 +157,16 @@ void allMethodsMustFitWithinInstrumentationSafeLimit() throws Exception {
144157

145158
assertTrue(failures.isEmpty(),
146159
failures.size() + " method(s) too large for safe instrumentation:\n"
147-
+ String.join("\n", failures));
160+
+ String.join("\n", failures));
148161
}
149162

150163
// -----------------------------------------------------------------------
151164
// Test: named critical classes must be found
152165
// -----------------------------------------------------------------------
153166

154167
/**
155-
* Ensures the critical parser classes actually exist in the build output.
156-
* Catches misconfigured build paths that would silently skip all checks.
168+
* Ensures the critical parser classes actually exist in the build output. Catches misconfigured
169+
* build paths that would silently skip all checks.
157170
*/
158171
@Test
159172
void criticalClassesMustBePresent() throws Exception {
@@ -170,7 +183,7 @@ void criticalClassesMustBePresent() throws Exception {
170183
}
171184
assertTrue(found,
172185
className + ".class not found under " + classesDir
173-
+ " — check build configuration");
186+
+ " — check build configuration");
174187
}
175188
}
176189

@@ -184,7 +197,8 @@ void criticalClassesMustBePresent() throws Exception {
184197
private List<BytecodeSizeVerifier.Result> scanParserClasses() throws Exception {
185198
Path classesDir = findClassesDir();
186199
if (classesDir == null) {
187-
System.err.println("WARNING: compiled classes directory not found, skipping bytecode checks");
200+
System.err.println(
201+
"WARNING: compiled classes directory not found, skipping bytecode checks");
188202
return Collections.emptyList();
189203
}
190204

@@ -196,8 +210,7 @@ private List<BytecodeSizeVerifier.Result> scanParserClasses() throws Exception {
196210
}
197211

198212
/**
199-
* Locate the compiled classes directory.
200-
* Tries standard Gradle and Maven layouts.
213+
* Locate the compiled classes directory. Tries standard Gradle and Maven layouts.
201214
*/
202215
private Path findClassesDir() {
203216
// Try to infer from this test class's own location
@@ -217,14 +230,16 @@ private Path findClassesDir() {
217230
}
218231

219232
// Fallback: standard locations relative to working directory
220-
for (String candidate : new String[]{
233+
for (String candidate : new String[] {
221234
"build/classes/java/main",
222235
"target/classes",
223236
"build/classes/main",
224237
"out/production/classes"
225238
}) {
226239
Path p = Path.of(candidate);
227-
if (Files.isDirectory(p)) return p;
240+
if (Files.isDirectory(p)) {
241+
return p;
242+
}
228243
}
229244
return null;
230245
}

src/test/java/net/sf/jsqlparser/parser/BytecodeSizeVerifier.java

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@
77
import java.util.stream.*;
88

99
/**
10-
* Zero-dependency bytecode verifier that scans compiled .class files
11-
* and reports methods approaching or exceeding the JVM 64KB code size limit.
10+
* Zero-dependency bytecode verifier that scans compiled .class files and reports methods
11+
* approaching or exceeding the JVM 64KB code size limit.
1212
*
13-
* Also checks clinit (static initializer) sizes separately since
14-
* large static initializers are a common problem with generated parsers.
13+
* Also checks clinit (static initializer) sizes separately since large static initializers are a
14+
* common problem with generated parsers.
1515
*
16-
* Usage as standalone tool:
17-
* java BytecodeSizeVerifier path/to/classes [--warn-pct 75] [--fail]
16+
* Usage as standalone tool: java BytecodeSizeVerifier path/to/classes [--warn-pct 75] [--fail]
1817
*
19-
* Usage as library (from JUnit test):
20-
* BytecodeSizeVerifier.Result r = BytecodeSizeVerifier.verify(classFile, 80);
21-
* assertTrue(r.violations.isEmpty(), r.report());
18+
* Usage as library (from JUnit test): BytecodeSizeVerifier.Result r =
19+
* BytecodeSizeVerifier.verify(classFile, 80); assertTrue(r.violations.isEmpty(), r.report());
2220
*/
2321
public class BytecodeSizeVerifier {
2422

@@ -113,7 +111,8 @@ public String toString() {
113111

114112
/**
115113
* Verify a single .class file.
116-
* @param classFile path to the .class file
114+
*
115+
* @param classFile path to the .class file
117116
* @param warnPercent warn when method exceeds this % of the 64KB limit (e.g. 75)
118117
*/
119118
public static Result verify(Path classFile, int warnPercent) throws IOException {
@@ -123,11 +122,13 @@ public static Result verify(Path classFile, int warnPercent) throws IOException
123122

124123
/**
125124
* Verify class bytes directly.
126-
* @param name descriptive name for reporting
127-
* @param classBytes raw .class file bytes
125+
*
126+
* @param name descriptive name for reporting
127+
* @param classBytes raw .class file bytes
128128
* @param warnPercent warn threshold (0-100)
129129
*/
130-
public static Result verify(String name, byte[] classBytes, int warnPercent) throws IOException {
130+
public static Result verify(String name, byte[] classBytes, int warnPercent)
131+
throws IOException {
131132
DataInputStream in = new DataInputStream(new ByteArrayInputStream(classBytes));
132133

133134
int magic = in.readInt();
@@ -149,21 +150,31 @@ public static Result verify(String name, byte[] classBytes, int warnPercent) thr
149150
case 1: // CONSTANT_Utf8
150151
cpUtf8[i] = in.readUTF();
151152
break;
152-
case 3: case 4: // Integer, Float
153+
case 3:
154+
case 4: // Integer, Float
153155
in.readInt();
154156
break;
155-
case 5: case 6: // Long, Double
157+
case 5:
158+
case 6: // Long, Double
156159
in.readLong();
157160
i++; // takes two CP slots
158161
break;
159162
case 7: // CONSTANT_Class
160163
cpClassNameIdx[i] = in.readUnsignedShort();
161164
break;
162-
case 8: case 16: case 19: case 20:
165+
case 8:
166+
case 16:
167+
case 19:
168+
case 20:
163169
// String, MethodType, Module, Package
164170
in.readUnsignedShort();
165171
break;
166-
case 9: case 10: case 11: case 12: case 17: case 18:
172+
case 9:
173+
case 10:
174+
case 11:
175+
case 12:
176+
case 17:
177+
case 18:
167178
// Fieldref, Methodref, InterfaceMethodref, NameAndType, Dynamic, InvokeDynamic
168179
in.readUnsignedShort();
169180
in.readUnsignedShort();
@@ -173,7 +184,8 @@ public static Result verify(String name, byte[] classBytes, int warnPercent) thr
173184
in.readUnsignedShort();
174185
break;
175186
default:
176-
throw new IOException("Unknown CP tag: " + tag + " at index " + i + " in " + name);
187+
throw new IOException(
188+
"Unknown CP tag: " + tag + " at index " + i + " in " + name);
177189
}
178190
}
179191

@@ -194,7 +206,9 @@ public static Result verify(String name, byte[] classBytes, int warnPercent) thr
194206
in.readUnsignedShort(); // super class
195207

196208
int ifCount = in.readUnsignedShort();
197-
for (int i = 0; i < ifCount; i++) in.readUnsignedShort();
209+
for (int i = 0; i < ifCount; i++) {
210+
in.readUnsignedShort();
211+
}
198212

199213
// Fields - skip
200214
int fieldCount = in.readUnsignedShort();
@@ -244,7 +258,8 @@ public static List<Result> verifyDirectory(Path dir, int warnPercent) throws IOE
244258
List<Result> results = new ArrayList<>();
245259
Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
246260
@Override
247-
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
261+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
262+
throws IOException {
248263
if (file.toString().endsWith(".class")) {
249264
results.add(verify(file, warnPercent));
250265
}
@@ -343,7 +358,9 @@ public static void main(String[] args) throws Exception {
343358
for (Result result : results) {
344359
if (!result.violations.isEmpty() || !result.warnings.isEmpty()) {
345360
System.out.println(result.report());
346-
if (!result.violations.isEmpty()) hasViolations = true;
361+
if (!result.violations.isEmpty()) {
362+
hasViolations = true;
363+
}
347364
}
348365
}
349366

src/test/java/net/sf/jsqlparser/parser/CCJSqlParserUtilTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ public void execute() throws Throwable {
408408

409409
@Test
410410
@Disabled
411-
//@todo: check if this still has a chance to timeout since we got too fast
411+
// @todo: check if this still has a chance to timeout since we got too fast
412412
public void testTimeOutIssue1582() {
413413
// This statement is INVALID on purpose
414414
// There are crafted INTO keywords in order to make it fail but only after a long time (40

src/test/java/net/sf/jsqlparser/test/TestUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,7 @@ public static void assertExpressionCanBeParsedAndDeparsed(String expressionStr,
373373
Expression expression = CCJSqlParserUtil.parseExpression(expressionStr);
374374
assertEquals(
375375
buildSqlString(expressionStr, laxDeparsingCheck),
376-
buildSqlString(expression.toString(), laxDeparsingCheck)
377-
);
376+
buildSqlString(expression.toString(), laxDeparsingCheck));
378377
} catch (JSQLParserException ex) {
379378
throw new JSQLParserException(expressionStr, ex);
380379
}

0 commit comments

Comments
 (0)