[Git][java-team/jboss-classfilewriter][master] 4 commits: Declare compliance with Debian Policy 4.1.5.

Markus Koschany gitlab at salsa.debian.org
Sat Jul 7 20:58:39 BST 2018


Markus Koschany pushed to branch master at Debian Java Maintainers / jboss-classfilewriter


Commits:
565d76e7 by Markus Koschany at 2018-07-07T21:42:32+02:00
Declare compliance with Debian Policy 4.1.5.

- - - - -
55da2741 by Markus Koschany at 2018-07-07T21:53:58+02:00
New upstream version 1.2.3
- - - - -
e01d6c08 by Markus Koschany at 2018-07-07T21:54:03+02:00
Update upstream source from tag 'upstream/1.2.3'

Update to upstream version '1.2.3'
with Debian dir 6918793e681ef348254925a3806d720a45d4108e
- - - - -
316f2d72 by Markus Koschany at 2018-07-07T21:54:37+02:00
Update changelog

- - - - -


4 changed files:

- debian/changelog
- debian/control
- pom.xml
- src/main/java/org/jboss/classfilewriter/ClassFile.java


Changes:

=====================================
debian/changelog
=====================================
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+jboss-classfilewriter (1.2.3-1) unstable; urgency=medium
+
+  * New upstream version 1.2.3.
+  * Declare compliance with Debian Policy 4.1.5.
+
+ -- Markus Koschany <apo at debian.org>  Sat, 07 Jul 2018 21:54:20 +0200
+
 jboss-classfilewriter (1.2.2-2) unstable; urgency=medium
 
   * libjboss-classfilewriter-java.poms: Remove --has-package-version flag.


=====================================
debian/control
=====================================
--- a/debian/control
+++ b/debian/control
@@ -12,7 +12,7 @@ Build-Depends:
  libmaven-javadoc-plugin-java,
  libmaven-bundle-plugin-java,
  maven-debian-helper (>= 1.5)
-Standards-Version: 4.1.3
+Standards-Version: 4.1.5
 Vcs-Git: https://anonscm.debian.org/git/pkg-java/jboss-classfilewriter.git
 Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/jboss-classfilewriter.git
 Homepage: https://github.com/jbossas/jboss-classfilewriter


=====================================
pom.xml
=====================================
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
 
     <groupId>org.jboss.classfilewriter</groupId>
     <artifactId>jboss-classfilewriter</artifactId>
-    <version>1.2.2.Final</version>
+    <version>1.2.3.Final</version>
 
     <packaging>jar</packaging>
     <description>A bytecode writer that creates .class files at runtime</description>


=====================================
src/main/java/org/jboss/classfilewriter/ClassFile.java
=====================================
--- a/src/main/java/org/jboss/classfilewriter/ClassFile.java
+++ b/src/main/java/org/jboss/classfilewriter/ClassFile.java
@@ -19,6 +19,7 @@ package org.jboss.classfilewriter;
 
 import java.io.IOException;
 import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
@@ -104,6 +105,8 @@ public class ClassFile implements WritableEntry {
         this.attributes.add(runtimeVisibleAnnotationsAttribute);
     }
 
+    private final static java.lang.reflect.Method defineClass1, defineClass2;
+
     public void addInterface(String iface) {
         this.interfaces.add(iface);
     }
@@ -282,7 +285,16 @@ public class ClassFile implements WritableEntry {
                 sm.checkPermission(permission);
             }
             byte[] b = toBytecode();
-            return UNSAFE.defineClass(name.replace('/', '.'), b, 0, b.length, loader, domain );
+            java.lang.reflect.Method method;
+            Object[] args;
+            if (domain == null) {
+                method = defineClass1;
+                args = new Object[] { name.replace('/', '.'), b, Integer.valueOf(0), Integer.valueOf(b.length) };
+            } else {
+                method = defineClass2;
+                args = new Object[] { name.replace('/', '.'), b, Integer.valueOf(0), Integer.valueOf(b.length), domain };
+            }
+            return (Class<?>) method.invoke(loader, args);
         } catch (RuntimeException e) {
             throw e;
         } catch (Exception e) {
@@ -368,27 +380,40 @@ public class ClassFile implements WritableEntry {
 
     // Unsafe mechanics
 
-    private static final sun.misc.Unsafe UNSAFE;
     static {
         try {
-            UNSAFE = getUnsafe();
-        } catch (Exception e) {
-            throw new Error(e);
-        }
-    }
-
-    private static Unsafe getUnsafe() {
-        if (System.getSecurityManager() != null) {
-            return new PrivilegedAction<Unsafe>() {
-                public Unsafe run() {
-                    return getUnsafe0();
+            Method[] defineClassMethods = AccessController.doPrivileged(new PrivilegedExceptionAction<Method[]>() {
+                public Method[] run() throws Exception {
+                    final sun.misc.Unsafe UNSAFE;
+                    final long overrideOffset;
+                    // first we need to grab Unsafe
+                    try {
+                        UNSAFE = getUnsafe();
+                        overrideOffset = UNSAFE.objectFieldOffset(AccessibleObject.class.getDeclaredField("override"));
+                    } catch (Exception e) {
+                        throw new Error(e);
+                    }
+                    // now we gain access to CL.defineClass methods
+                    Class<?> cl = ClassLoader.class;
+                    Method defClass1 = cl.getDeclaredMethod("defineClass", new Class[] { String.class, byte[].class, int.class,
+                        int.class });
+                    Method defClass2 = cl.getDeclaredMethod("defineClass", new Class[] { String.class, byte[].class, int.class,
+                        int.class, ProtectionDomain.class });
+                    // use Unsafe to crack open both CL.defineClass() methods (instead of using setAccessible())
+                    UNSAFE.putBoolean(defClass1, overrideOffset, true);
+                    UNSAFE.putBoolean(defClass2, overrideOffset, true);
+                    return new Method[]{defClass1, defClass2};
                 }
-            }.run();
+            });
+            // set methods to final fields
+            defineClass1 = defineClassMethods[0];
+            defineClass2 = defineClassMethods[1];
+        } catch (PrivilegedActionException pae) {
+            throw new RuntimeException("cannot initialize ClassFile", pae.getException());
         }
-        return getUnsafe0();
     }
 
-    private static Unsafe getUnsafe0()  {
+    private static Unsafe getUnsafe()  {
         try {
             Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
             theUnsafe.setAccessible(true);



View it on GitLab: https://salsa.debian.org/java-team/jboss-classfilewriter/compare/f9f5e873ca9570e2f073e3bc290e757a4f63caf1...316f2d720bf9c4964139b5312db5b28c31f2310f

-- 
View it on GitLab: https://salsa.debian.org/java-team/jboss-classfilewriter/compare/f9f5e873ca9570e2f073e3bc290e757a4f63caf1...316f2d720bf9c4964139b5312db5b28c31f2310f
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20180707/440fb8fe/attachment.html>


More information about the pkg-java-commits mailing list