This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 335baf58fb Set Guice class loading to CHILD - avoid using terminally 
deprecated methods
335baf58fb is described below

commit 335baf58fb499ee4e14cd1fe0c3cc2c1c9ed4ffe
Author: Slawomir Jaranowski <s.jaranow...@gmail.com>
AuthorDate: Wed Jul 23 23:37:28 2025 +0200

    Set Guice class loading to CHILD - avoid using terminally deprecated methods
    
    Default Guice class loading uses a terminally deprecated JDK memory-access 
classes.
    
    Fix #10312
---
 .../apache/maven/cling/invoker/LookupInvoker.java  | 11 ++++
 ...10312TerminallyDeprecatedMethodInGuiceTest.java | 75 ++++++++++++++++++++++
 .../org/apache/maven/it/TestSuiteOrdering.java     |  1 +
 .../pom.xml                                        | 11 ++++
 .../main/java/org/apache/maven/it/Verifier.java    | 16 ++++-
 5 files changed, 112 insertions(+), 2 deletions(-)

diff --git 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
index f8390c6282..ec439870cf 100644
--- 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
+++ 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
@@ -149,6 +149,7 @@ protected int doInvoke(C context) throws Exception {
         validate(context);
         pushCoreProperties(context);
         pushUserProperties(context);
+        setupGuiceClassLoading(context);
         configureLogging(context);
         createTerminal(context);
         activateLogging(context);
@@ -247,6 +248,16 @@ protected void pushUserProperties(C context) throws 
Exception {
         }
     }
 
+    /**
+     * Sets up Guice class loading mode to CHILD, if not already set.
+     * Default Guice class loading mode uses a terminally deprecated JDK 
memory-access classes.
+     */
+    protected void setupGuiceClassLoading(C context) {
+        if (System.getProperty("guice_custom_class_loading", "").isBlank()) {
+            System.setProperty("guice_custom_class_loading", "CHILD");
+        }
+    }
+
     protected void configureLogging(C context) throws Exception {
         // LOG COLOR
         Map<String, String> effectiveProperties = 
context.protoSession.getEffectiveProperties();
diff --git 
a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.java
 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.java
new file mode 100644
index 0000000000..2c5c6ed8a3
--- /dev/null
+++ 
b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.it;
+
+import java.io.File;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * This is a test set for <a 
href="https://github.com/apache/maven/issues/10312";>GH-10312</a>.
+ */
+class MavenITgh10312TerminallyDeprecatedMethodInGuiceTest extends 
AbstractMavenIntegrationTestCase {
+
+    MavenITgh10312TerminallyDeprecatedMethodInGuiceTest() {
+        super(ALL_MAVEN_VERSIONS);
+    }
+
+    @Test
+    void worryingShouldNotBePrinted() throws Exception {
+        requiresJavaVersion("[24,)");
+        File testDir = 
extractResources("/gh-10312-terminally-deprecated-method-in-guice");
+
+        Verifier verifier = new Verifier(testDir.getAbsolutePath());
+        verifier.setForkJvm(true);
+        verifier.addCliArgument("validate");
+        verifier.execute();
+
+        assertTrue(verifier.getStdout().isEmpty(), "Expected no output on 
stdout, but got: " + verifier.getStdout());
+
+        assertFalse(
+                verifier.getStderr()
+                        .contains(
+                                "WARNING: sun.misc.Unsafe::staticFieldBase has 
been called by com.google.inject.internal.aop.HiddenClassDefiner"),
+                "Expected no warning about sun.misc.Unsafe::staticFieldBase, 
but got: " + verifier.getStderr());
+    }
+
+    @Test
+    void allowOverwriteByUser() throws Exception {
+        requiresJavaVersion("[24,26)");
+        File testDir = 
extractResources("/gh-10312-terminally-deprecated-method-in-guice");
+
+        Verifier verifier = new Verifier(testDir.getAbsolutePath());
+        verifier.setForkJvm(true);
+        verifier.addCliArgument("validate");
+        verifier.addCliArgument("-Dguice_custom_class_loading=BRIDGE");
+        verifier.execute();
+
+        assertTrue(verifier.getStdout().isEmpty(), "Expected no output on 
stdout, but got: " + verifier.getStdout());
+
+        assertTrue(
+                verifier.getStderr()
+                        .contains(
+                                "WARNING: sun.misc.Unsafe::staticFieldBase has 
been called by com.google.inject.internal.aop.HiddenClassDefiner"),
+                "Expected warning about sun.misc.Unsafe::staticFieldBase, but 
got: " + verifier.getStderr());
+    }
+}
diff --git 
a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java 
b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
index d931454b06..3bd40ee2d6 100644
--- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
+++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java
@@ -103,6 +103,7 @@ public TestSuiteOrdering() {
          * the tests are to finishing. Newer tests are also more likely to 
fail, so this is
          * a fail fast technique as well.
          */
+        
suite.addTestSuite(MavenITgh10312TerminallyDeprecatedMethodInGuiceTest.class);
         suite.addTestSuite(MavenITgh10937QuotedPipesInMavenOptsTest.class);
         
suite.addTestSuite(MavenITgh2532DuplicateDependencyEffectiveModelTest.class);
         suite.addTestSuite(MavenITmng8736ConcurrentFileActivationTest.class);
diff --git 
a/its/core-it-suite/src/test/resources/gh-10312-terminally-deprecated-method-in-guice/pom.xml
 
b/its/core-it-suite/src/test/resources/gh-10312-terminally-deprecated-method-in-guice/pom.xml
new file mode 100644
index 0000000000..688f859a22
--- /dev/null
+++ 
b/its/core-it-suite/src/test/resources/gh-10312-terminally-deprecated-method-in-guice/pom.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.gh2532</groupId>
+  <artifactId>parent</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+</project>
diff --git 
a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java
 
b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java
index 75367b8c83..7f6d1794ed 100644
--- 
a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java
+++ 
b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java
@@ -124,6 +124,10 @@ public class Verifier {
 
     private boolean skipMavenRc = true;
 
+    private ByteArrayOutputStream stdout;
+
+    private ByteArrayOutputStream stderr;
+
     public Verifier(String basedir) throws VerificationException {
         this(basedir, null);
     }
@@ -240,8 +244,8 @@ public void execute() throws VerificationException {
             if (forkJvm) {
                 mode = ExecutorHelper.Mode.FORKED;
             }
-            ByteArrayOutputStream stdout = new ByteArrayOutputStream();
-            ByteArrayOutputStream stderr = new ByteArrayOutputStream();
+            stdout = new ByteArrayOutputStream();
+            stderr = new ByteArrayOutputStream();
             ExecutorRequest request = 
builder.stdOut(stdout).stdErr(stderr).build();
             int ret = executorHelper.execute(mode, request);
             if (ret > 0) {
@@ -472,6 +476,14 @@ public void verifyTextInLog(String text) throws 
VerificationException {
         }
     }
 
+    public String getStdout() {
+        return stdout != null ? stdout.toString(StandardCharsets.UTF_8) : "";
+    }
+
+    public String getStderr() {
+        return stderr != null ? stderr.toString(StandardCharsets.UTF_8) : "";
+    }
+
     public static String stripAnsi(String msg) {
         return msg.replaceAll("\u001B\\[[;\\d]*[ -/]*[@-~]", "");
     }

Reply via email to