changeset 5741:16f2865aac24

7190750: (pack200) the java unpacker produces non spec. compliant classfile with lambda classfiles Reviewed-by: jrose
author ksrini
date Fri, 17 Aug 2012 08:28:48 -0700
parents 509421263cdd
children a2359f0f9533
files src/share/classes/com/sun/java/util/jar/pack/ClassWriter.java
diffstat 1 files changed, 21 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/java/util/jar/pack/ClassWriter.java	Fri Aug 17 12:51:23 2012 -0700
+++ b/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);