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

Markus Koschany (@apo) gitlab at salsa.debian.org
Sat Nov 12 20:18:38 GMT 2022



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


Commits:
882fd4ce by Markus Koschany at 2022-11-12T16:12:11+01:00
Declare compliance with Debian Policy 4.6.1.

- - - - -
d520d7a0 by Markus Koschany at 2022-11-12T16:12:24+01:00
Update copyright years

- - - - -
5d1417cf by Markus Koschany at 2022-11-12T16:12:39+01:00
New upstream version 1.3.0
- - - - -
a63c62ec by Markus Koschany at 2022-11-12T16:12:40+01:00
Update upstream source from tag 'upstream/1.3.0'

Update to upstream version '1.3.0'
with Debian dir 277a10755b5b96c4db5f5bae0fd5801652fe9a89
- - - - -
8b9dbcd0 by Markus Koschany at 2022-11-12T16:15:44+01:00
Update changelog

- - - - -


7 changed files:

- + .github/workflows/ci.yml
- debian/changelog
- debian/control
- debian/copyright
- pom.xml
- src/main/java/org/jboss/classfilewriter/ClassFile.java
- src/main/java/org/jboss/classfilewriter/DefaultClassFactory.java


Changes:

=====================================
.github/workflows/ci.yml
=====================================
@@ -0,0 +1,45 @@
+# This workflow will build a Java project with Maven
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: JBoss Class File Writer CI
+
+on:
+  pull_request:
+    types: [opened, synchronize, reopened, ready_for_review]
+
+jobs:
+  build-test-matrix:
+    name: ${{ matrix.impl}}-${{ matrix.jdk }}-${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    timeout-minutes: 10
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-20.04, windows-latest]
+        jdk: [11, 17]
+        impl: [hotspot, openj9]
+    steps:
+    - name: Configure runner - Linux 
+      if: contains(matrix.os, 'ubuntu')
+      run: |
+        sudo bash -c "echo '127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4' > /etc/hosts"
+        sudo bash -c "echo '::1         localhost localhost.localdomain localhost6 localhost6.localdomain6' >> /etc/hosts"
+    - name: Configure Runner - Windows
+      if: contains(matrix.os, 'windows')
+      run: |
+        echo '127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4' > %SystemRoot%\System32\drivers\etc\hosts
+        echo '::1         localhost localhost.localdomain localhost6 localhost6.localdomain6' >> %SystemRoot%\System32\drivers\etc\hosts
+      shell: cmd
+    - uses: actions/checkout at v2
+    - name: Set up JDK ${{ matrix.jdk }}
+      uses: AdoptOpenJDK/install-jdk at v1
+      with:
+        version: ${{ matrix.jdk }}
+        impl: ${{ matrix.impl }}
+    - name: Run Tests
+      run: mvn -ntp -U -B -fae clean install
+    - uses: actions/upload-artifact at v2
+      if: failure()
+      with:
+        name: surefire-reports-${{ matrix.openjdk}}-${{ matrix.jdk }}-${{ matrix.os }}
+        path: '**/surefire-reports/*.txt'


=====================================
debian/changelog
=====================================
@@ -1,3 +1,10 @@
+jboss-classfilewriter (1.3.0-1) unstable; urgency=medium
+
+  * New upstream version 1.3.0. Supports OpenJDK 17. (Closes: #1012081)
+  * Declare compliance with Debian Policy 4.6.1.
+
+ -- Markus Koschany <apo at debian.org>  Sat, 12 Nov 2022 16:13:00 +0100
+
 jboss-classfilewriter (1.2.5-1) unstable; urgency=medium
 
   * New upstream version 1.2.5.


=====================================
debian/control
=====================================
@@ -12,7 +12,7 @@ Build-Depends:
  libmaven-javadoc-plugin-java,
  libmaven-bundle-plugin-java,
  maven-debian-helper (>= 1.5)
-Standards-Version: 4.6.0
+Standards-Version: 4.6.1
 Vcs-Git: https://salsa.debian.org/java-team/jboss-classfilewriter.git
 Vcs-Browser: https://salsa.debian.org/java-team/jboss-classfilewriter
 Homepage: https://github.com/jbossas/jboss-classfilewriter


=====================================
debian/copyright
=====================================
@@ -3,11 +3,11 @@ Upstream-Name: classfilewriter
 Source: https://github.com/jbossas/jboss-classfilewriter
 
 Files: *
-Copyright: 2015-2019, Stuart Douglas <sdouglas at redhat.com>
+Copyright: 2015-2022, Stuart Douglas <sdouglas at redhat.com>
 License: Apache-2.0
 
 Files: debian/*
-Copyright: 2015-2021, Markus Koschany <apo at debian.org>
+Copyright: 2015-2022, Markus Koschany <apo at debian.org>
 License: Apache-2.0
 
 License: Apache-2.0


=====================================
pom.xml
=====================================
@@ -4,12 +4,12 @@
     <parent>
         <groupId>org.jboss</groupId>
         <artifactId>jboss-parent</artifactId>
-        <version>24</version>
+        <version>39</version>
     </parent>
 
     <groupId>org.jboss.classfilewriter</groupId>
     <artifactId>jboss-classfilewriter</artifactId>
-    <version>1.2.5.Final</version>
+    <version>1.3.0.Final</version>
 
     <packaging>jar</packaging>
     <description>A bytecode writer that creates .class files at runtime</description>
@@ -32,6 +32,9 @@
     </licenses>
 
     <properties>
+        <jdk.min.version>11</jdk.min.version>
+        <maven.compiler.source>11</maven.compiler.source>
+        <maven.compiler.target>11</maven.compiler.target>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 
@@ -39,7 +42,7 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.13.1</version>
+            <version>4.13.2</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
@@ -53,7 +56,7 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
-                    <forkMode>once</forkMode>
+                    <argLine>--add-opens=java.base/java.lang=ALL-UNNAMED</argLine>
                 </configuration>
             </plugin>
             <plugin>


=====================================
src/main/java/org/jboss/classfilewriter/ClassFile.java
=====================================
@@ -39,6 +39,7 @@ import org.jboss.classfilewriter.util.DescriptorUtils;
 
 /**
  * @author Stuart Douglas
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
  */
 public class ClassFile implements WritableEntry {
 
@@ -90,18 +91,7 @@ public class ClassFile implements WritableEntry {
 
     @Deprecated
     public ClassFile(String name, int accessFlags, String superclass, int version, ClassLoader classLoader, String... interfaces) {
-        if(version > JavaVersions.JAVA_6 && classLoader == null) {
-            throw new IllegalArgumentException("ClassLoader must be specified if version is greater than Java 6");
-        }
-        this.version = version;
-        this.classLoader = classLoader;
-        this.classFactory = null; // allowed to be null for backward compatibility reasons
-        this.name = name.replace('/', '.'); // store the name in . form
-        this.superclass = superclass;
-        this.accessFlags = accessFlags;
-        this.interfaces.addAll(Arrays.asList(interfaces));
-        this.runtimeVisibleAnnotationsAttribute = new AnnotationsAttribute(AnnotationsAttribute.Type.RUNTIME_VISIBLE, constPool);
-        this.attributes.add(runtimeVisibleAnnotationsAttribute);
+        this(name, accessFlags, superclass, version, classLoader, DefaultClassFactory.INSTANCE, interfaces);
     }
 
     public ClassFile(String name, String superclass, ClassLoader classLoader, ClassFactory classFactory, String... interfaces) {
@@ -295,7 +285,6 @@ public class ClassFile implements WritableEntry {
 
     private Class<?> defineInternal(ClassLoader loader, ProtectionDomain domain) {
         byte[] b = toBytecode();
-        final ClassFactory classFactory = this.classFactory == null ? DefaultClassFactory.INSTANCE : this.classFactory;
         return classFactory.defineClass(loader, name, b, 0, b.length, domain);
     }
 


=====================================
src/main/java/org/jboss/classfilewriter/DefaultClassFactory.java
=====================================
@@ -17,61 +17,47 @@
  */
 package org.jboss.classfilewriter;
 
-import sun.misc.Unsafe;
-
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.security.AccessController;
-import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.security.ProtectionDomain;
 
 /**
- * Default class definition factory. This factory maintains backward compatibility
- * but it doesn't work on JDK 12 and above where ClassLoader reflection magic is forbidden.
+ * Default class definition factory.
  *
  * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
  */
 final class DefaultClassFactory implements ClassFactory {
 
-    static final ClassFactory INSTANCE = new DefaultClassFactory();
-
-    private final java.lang.reflect.Method defineClass1, defineClass2;
+    private static final String DEFINE_CLASS_METHOD_NAME = "defineClass";
+    private static final MethodHandle defineClassWithoutDomainParam, defineClassWithDomainParam;
 
-    private DefaultClassFactory() {
+    static {
+        MethodHandle[] defineClassMethods;
         try {
-            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 {
-                        Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
-                        theUnsafe.setAccessible(true);
-                        UNSAFE = (Unsafe) theUnsafe.get(null);
-                        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};
+            MethodHandles.Lookup LOOKUP = MethodHandles.privateLookupIn(ClassLoader.class, MethodHandles.lookup());
+            defineClassMethods = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
+                public MethodHandle[] run() throws Exception {
+                    MethodHandle defineClass1 = LOOKUP.findVirtual(ClassLoader.class, DEFINE_CLASS_METHOD_NAME,
+                            MethodType.methodType(Class.class, String.class, byte[].class, int.class, int.class));
+                    MethodHandle defineClass2 = LOOKUP.findVirtual(ClassLoader.class, DEFINE_CLASS_METHOD_NAME,
+                            MethodType.methodType(Class.class, String.class, byte[].class, int.class, int.class, ProtectionDomain.class));
+                    return new MethodHandle[]{defineClass1, defineClass2};
                 }
             });
-            // set methods to volatile fields
-            defineClass1 = defineClassMethods[0];
-            defineClass2 = defineClassMethods[1];
-        } catch (PrivilegedActionException pae) {
-            throw new RuntimeException("Cannot initialize DefaultClassFactory", pae.getException());
+        } catch (Throwable t) {
+            throw new RuntimeException("Cannot initialize " + DefaultClassFactory.class.getName(), t);
         }
+        defineClassWithoutDomainParam = defineClassMethods[0];
+        defineClassWithDomainParam = defineClassMethods[1];
+    }
+
+    static final ClassFactory INSTANCE = new DefaultClassFactory();
+
+    private DefaultClassFactory() {
+        // forbidden instantiation
     }
 
     @Override
@@ -91,19 +77,14 @@ final class DefaultClassFactory implements ClassFactory {
                 RuntimePermission permission = new RuntimePermission("defineClassInPackage." + packageName);
                 sm.checkPermission(permission);
             }
-            java.lang.reflect.Method method;
-            Object[] args;
             if (domain == null) {
-                method = defineClass1;
-                args = new Object[]{name, b, 0, b.length};
+                return (Class<?>) defineClassWithoutDomainParam.invokeExact(loader, name, b, 0, b.length);
             } else {
-                method = defineClass2;
-                args = new Object[]{name, b, 0, b.length, domain};
+                return (Class<?>) defineClassWithDomainParam.invokeExact(loader, name, b, 0, b.length, domain);
             }
-            return (Class<?>) method.invoke(loader, args);
         } catch (RuntimeException e) {
             throw e;
-        } catch (Exception e) {
+        } catch (Throwable e) {
             throw new RuntimeException(e);
         }
     }



View it on GitLab: https://salsa.debian.org/java-team/jboss-classfilewriter/-/compare/1b48b55e16ae54eab77b613a67ffbb9347174fff...8b9dbcd06db6de40a402f995274811333221a1be

-- 
View it on GitLab: https://salsa.debian.org/java-team/jboss-classfilewriter/-/compare/1b48b55e16ae54eab77b613a67ffbb9347174fff...8b9dbcd06db6de40a402f995274811333221a1be
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/20221112/daa982e7/attachment.htm>


More information about the pkg-java-commits mailing list