Skip to content

Commit 3dd2be7

Browse files
authored
Fix Jackson ServiceConfigurationError caused by NetBeans classloader conflict (#279)
* Indentation corrected This reverts commit 9b1c425. * Fix Jackson ServiceConfigurationError caused by NetBeans classloader conflict * Use Plugin ClassLoader for fallback * usePluginClassLoader in pairProgrammer
1 parent 3ea6228 commit 3dd2be7

3 files changed

Lines changed: 55 additions & 10 deletions

File tree

src/main/java/io/github/jeddict/ai/hints/AssistantChatManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2025 the original author or authors from the Jeddict project (https://jeddict.github.io/).
2+
* Copyright 2025-26 the original author or authors from the Jeddict project (https://jeddict.github.io/).
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of

src/main/java/io/github/jeddict/ai/lang/JeddictBrain.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2025 the original author or authors from the Jeddict project (https://jeddict.github.io/).
2+
* Copyright 2025-26 the original author or authors from the Jeddict project (https://jeddict.github.io/).
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
55
* use this file except in compliance with the License. You may obtain a copy of
@@ -52,6 +52,7 @@
5252
import io.github.jeddict.ai.agent.pair.HackerWithoutTools;
5353
import io.github.jeddict.ai.agent.pair.PairProgrammer;
5454
import static io.github.jeddict.ai.lang.InteractionMode.INTERACTIVE;
55+
import io.github.jeddict.ai.util.ClassLoaderUtil;
5556
import io.github.jeddict.ai.util.PropertyChangeEmitter;
5657
import java.lang.reflect.InvocationTargetException;
5758
import org.openide.DialogDisplayer;
@@ -209,6 +210,7 @@ public JeddictBrain withMemory(int size) {
209210
* @return an instance of the configured agent
210211
*/
211212
public <T> T pairProgrammer(PairProgrammer.Specialist specialist) {
213+
ClassLoaderUtil.usePluginClassLoaderIfNeeded(getClass());
212214
ChatModel chatModel = null;
213215

214216
if (specialist == PairProgrammer.Specialist.HACKER) {
@@ -335,18 +337,23 @@ protected boolean probeToolSupport() {
335337
);
336338

337339
return toolsSupport;
338-
} catch (final NoClassDefFoundError e) {
339-
LOG.severe(() ->
340-
"error probing tool support (conflicting classpath), returning false %s\n%s".formatted(
341-
e.toString(),
342-
Arrays.toString(e.getStackTrace())
343-
)
340+
} catch (final NoClassDefFoundError | java.util.ServiceConfigurationError e) {
341+
342+
LOG.severe(()
343+
-> "Error probing tool support (likely classloader conflict), returning false %s\n%s".formatted(
344+
e.toString(),
345+
Arrays.toString(e.getStackTrace())
346+
)
344347
);
348+
349+
ClassLoaderUtil.enablePluginClassLoaderFallback();
350+
345351
final NotifyDescriptor nd = new NotifyDescriptor.Message(
346-
"AI tool support probe failed due to a conflicting classpath issue: " + e.toString(),
347-
NotifyDescriptor.ERROR_MESSAGE
352+
"AI tool support probe failed due to a classpath conflict: " + e.toString(),
353+
NotifyDescriptor.ERROR_MESSAGE
348354
);
349355
DialogDisplayer.getDefault().notify(nd);
356+
350357
} catch (final Throwable t) {
351358
LOG.severe(() ->
352359
"error probing tool support, returning false %s\n%s".formatted(
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2026 the original author or authors from the Jeddict project (https://jeddict.github.io/).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package io.github.jeddict.ai.util;
17+
18+
/**
19+
*
20+
* @author Gaurav Gupta
21+
*/
22+
public final class ClassLoaderUtil {
23+
24+
private static volatile boolean USE_PLUGIN_CLASSLOADER_FALLBACK = false;
25+
26+
private ClassLoaderUtil() {
27+
}
28+
29+
public static void usePluginClassLoaderIfNeeded(Class<?> clazz) {
30+
if (USE_PLUGIN_CLASSLOADER_FALLBACK) {
31+
Thread.currentThread().setContextClassLoader(clazz.getClassLoader());
32+
}
33+
}
34+
35+
public static void enablePluginClassLoaderFallback() {
36+
USE_PLUGIN_CLASSLOADER_FALLBACK = true;
37+
}
38+
}

0 commit comments

Comments
 (0)