]> source.dussan.org Git - javassist.git/commitdiff
Add test for 16th line & fix 492/head
authorakuznetsov <kuznet775@gmail.com>
Sat, 28 Sep 2024 18:06:53 +0000 (22:06 +0400)
committerakuznetsov <kuznet775@gmail.com>
Sat, 28 Sep 2024 18:06:53 +0000 (22:06 +0400)
src/main/javassist/bytecode/LineNumberAttributeBuilder.java
src/test/javassist/LineNumberTest.java

index 52d9d0c8cfbdaa4d7bee2af1e35579444a163812..25182e2de03f627f92c9ddbf1a796d940244fb1b 100644 (file)
@@ -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) {
index 7e9fbd2f56c0b21a129fff44458e6081115d04e7..4ab2580c7a526f37a43545129e19d80865e6d70f 100644 (file)
@@ -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 {