aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakuznetsov <kuznet775@gmail.com>2024-09-28 22:06:53 +0400
committerakuznetsov <kuznet775@gmail.com>2024-09-28 22:06:53 +0400
commit4520f0398769cfe6d7b436843041e676ebd5c2f9 (patch)
treef7bd7e2eafc950d671a7db41bf05ae46c862321e
parent3cf49c0e6a9a23eb609ef4831782f3f02124975c (diff)
downloadjavassist-4520f0398769cfe6d7b436843041e676ebd5c2f9.tar.gz
javassist-4520f0398769cfe6d7b436843041e676ebd5c2f9.zip
Add test for 16th line & fix
-rw-r--r--src/main/javassist/bytecode/LineNumberAttributeBuilder.java14
-rw-r--r--src/test/javassist/LineNumberTest.java18
2 files changed, 25 insertions, 7 deletions
diff --git a/src/main/javassist/bytecode/LineNumberAttributeBuilder.java b/src/main/javassist/bytecode/LineNumberAttributeBuilder.java
index 52d9d0c8..25182e2d 100644
--- a/src/main/javassist/bytecode/LineNumberAttributeBuilder.java
+++ b/src/main/javassist/bytecode/LineNumberAttributeBuilder.java
@@ -11,15 +11,15 @@ import java.util.Map;
public class LineNumberAttributeBuilder {
private final HashMap<Integer, Integer> map = new HashMap<>();
- public void put(int newPc, ASTree tree) {
+ public void put(int pc, ASTree tree) {
if (tree != null)
- put(newPc, tree.getLineNumber());
+ put(pc, tree.getLineNumber());
}
- private void put(int newPc, int lineNum) {
- Integer pc = map.get(lineNum);
- if (pc == null || newPc < pc) {
- map.put(lineNum, newPc);
+ private void put(int pc, int lineNum) {
+ Integer oldLineNum = map.get(pc);
+ if (oldLineNum == null || lineNum > oldLineNum) {
+ map.put(pc, lineNum);
}
}
@@ -29,8 +29,8 @@ public class LineNumberAttributeBuilder {
DataOutputStream dos = new DataOutputStream(bos)) {
dos.writeShort(size);
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
- dos.writeShort(entry.getValue());
dos.writeShort(entry.getKey());
+ dos.writeShort(entry.getValue());
}
return new LineNumberAttribute(cp, bos.toByteArray());
} catch (IOException e) {
diff --git a/src/test/javassist/LineNumberTest.java b/src/test/javassist/LineNumberTest.java
index 7e9fbd2f..4ab2580c 100644
--- a/src/test/javassist/LineNumberTest.java
+++ b/src/test/javassist/LineNumberTest.java
@@ -59,6 +59,24 @@ public class LineNumberTest extends TestCase {
"}"), 1, 5);
}
+ public void test16Line() {
+ doTestRuntime(String.join("\n",
+ "public void run() {",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "",
+ "throwException();",
+ "}"), 1, 16);
+ }
+
private void doTestCompile(String src, String msg) {
CtClass testClass = loader.makeClass("javassist.LineNumberCompileTest" + classNumber++);
try {