This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
The following commit(s) were added to refs/heads/master by this push:
new 74d4975d DAEMON-479 Check wrapped daemon classes in jsvc (#317)
74d4975d is described below
commit 74d4975d797fb4240e848af3a3d578f0adf5ccdd
Author: Aryan R. Ganjoo <[email protected]>
AuthorDate: Mon Nov 16 18:32:08 2026 +0530
DAEMON-479 Check wrapped daemon classes in jsvc (#317)
---
src/changes/changes.xml | 1 +
.../commons/daemon/support/DaemonLoader.java | 12 ++++-
.../commons/daemon/support/DaemonLoaderTest.java | 52 ++++++++++++++++++++++
3 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b04867ce..4a1dfa58 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,6 +44,7 @@
<!-- FIX -->
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix native build
with C23 boolean keywords (#319).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory, xzhiyouu">jsvc.
Prevent a heap buffer overflow when parsing jvm.cfg by rejecting configurations
with more than 255 resolvable JVM definitions.</action>
+ <action type="fix" issue="DAEMON-479" due-to="Aryan Ganjoo">Make jsvc
-check accept wrapped @ClassName services that DaemonLoader.load()
supports.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Mohd Irshad, Gary Gregory">Add
unit test for DaemonInitException.getMessageWithCause (#318).</action>
<!-- UPDATE -->
diff --git a/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java
b/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java
index 03eb826c..4e754540 100644
--- a/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java
+++ b/src/main/java/org/apache/commons/daemon/support/DaemonLoader.java
@@ -89,7 +89,17 @@ public final class DaemonLoader
}
/* Find the required class */
- final Class<?> c = cl.loadClass(className);
+ final Class<?> c;
+ if (className.charAt(0) == '@') {
+ /* Wrapped class, see load(): verify the real class can be
+ * found and check the DaemonWrapper that will host it.
+ */
+ cl.loadClass(className.substring(1));
+ c = DaemonWrapper.class;
+ }
+ else {
+ c = cl.loadClass(className);
+ }
/* This should _never_ happen, but double-checking doesn't harm */
if (c == null) {
diff --git
a/src/test/java/org/apache/commons/daemon/support/DaemonLoaderTest.java
b/src/test/java/org/apache/commons/daemon/support/DaemonLoaderTest.java
new file mode 100644
index 00000000..4481f719
--- /dev/null
+++ b/src/test/java/org/apache/commons/daemon/support/DaemonLoaderTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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
+ *
+ * https://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.commons.daemon.support;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link DaemonLoader}.
+ */
+class DaemonLoaderTest {
+
+ /**
+ * A plain application, as run by jsvc through DaemonWrapper with {@code
@className}.
+ */
+ public static class WrappedApplication {
+
+ public static void main(final String[] args) {
+ // empty
+ }
+ }
+
+ @Test
+ void testCheckDaemonClass() {
+ assertTrue(DaemonLoader.check(WrappedApplication.class.getName()));
+
assertFalse(DaemonLoader.check("org.apache.commons.daemon.DoesNotExist"));
+ }
+
+ @Test
+ void testCheckWrappedClass() {
+ // jsvc -check @className must accept what DaemonLoader.load() accepts.
+ assertTrue(DaemonLoader.check("@" +
WrappedApplication.class.getName()));
+
assertFalse(DaemonLoader.check("@org.apache.commons.daemon.DoesNotExist"));
+ }
+}