7190750: (pack200) the java unpacker produces non spec. compliant classfile with lambda classfiles
authorksrini
Fri, 17 Aug 2012 08:28:48 -0700
changeset 13577 afcb909fea86
parent 13576 850377563282
child 13578 cb435d74ab6b
7190750: (pack200) the java unpacker produces non spec. compliant classfile with lambda classfiles Reviewed-by: jrose
jdk/src/share/classes/com/sun/java/util/jar/pack/ClassWriter.java
--- a/jdk/src/share/classes/com/sun/java/util/jar/pack/ClassWriter.java	Fri Aug 17 12:51:23 2012 -0700
+++ b/jdk/src/share/classes/com/sun/java/util/jar/pack/ClassWriter.java	Fri Aug 17 08:28:48 2012 -0700
@@ -207,6 +207,22 @@
                         m);
     }
 
+    private void reorderBSMandICS(Attribute.Holder h) {
+        Attribute bsmAttr = h.getAttribute(Package.attrBootstrapMethodsEmpty);
+        if (bsmAttr == null) return;
+
+        Attribute icsAttr = h.getAttribute(Package.attrInnerClassesEmpty);
+        if (icsAttr == null) return;
+
+        int bsmidx = h.attributes.indexOf(bsmAttr);
+        int icsidx = h.attributes.indexOf(icsAttr);
+        if (bsmidx > icsidx) {
+            h.attributes.remove(bsmAttr);
+            h.attributes.add(icsidx, bsmAttr);
+        }
+        return;
+    }
+
     // handy buffer for collecting attrs
     ByteArrayOutputStream buf    = new ByteArrayOutputStream();
     DataOutputStream      bufOut = new DataOutputStream(buf);
@@ -216,6 +232,11 @@
             writeShort(0);  // attribute size
             return;
         }
+        // there may be cases if an InnerClass attribute is explicit, then the
+        // ordering could be wrong, fix the ordering before we write it out.
+        if (h instanceof Package.Class)
+            reorderBSMandICS(h);
+
         writeShort(h.attributes.size());
         for (Attribute a : h.attributes) {
             a.finishRefs(cpIndex);