Skip to content

Commit bd62644

Browse files
committedOct 14, 2024
8341924: Improve error message with structurally malformed Code array
Reviewed-by: asotona
1 parent a2c7752 commit bd62644

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
 

‎src/jdk.jdeps/share/classes/com/sun/tools/javap/CodeWriter.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -92,20 +92,22 @@ public void writeVerboseHeader(CodeAttribute attr) {
9292
public void writeInstrs(CodeAttribute attr) {
9393
List<InstructionDetailWriter> detailWriters = getDetailWriters(attr);
9494

95-
int pc = 0;
95+
int[] pcState = {0};
9696
try {
97-
for (var coe: attr) {
97+
attr.forEach(coe -> {
9898
if (coe instanceof Instruction instr) {
99-
for (InstructionDetailWriter w: detailWriters)
99+
int pc = pcState[0];
100+
for (InstructionDetailWriter w : detailWriters)
100101
w.writeDetails(pc, instr);
101102
writeInstr(pc, instr, attr);
102-
pc += instr.sizeInBytes();
103+
pcState[0] = pc + instr.sizeInBytes();
103104
}
104-
}
105+
});
105106
} catch (IllegalArgumentException e) {
106-
report("error at or after byte " + pc);
107+
report("error at or after address " + pcState[0] + ": " + e.getMessage());
107108
}
108109

110+
int pc = pcState[0];
109111
for (InstructionDetailWriter w: detailWriters)
110112
w.flush(pc);
111113
}

0 commit comments

Comments
 (0)
Please sign in to comment.