Skip to content

Commit ada8496

Browse files
Flossyclaude
andcommitted
fix: deprecate non-functional NexusClassSource MAVEN mode
- Add @deprecated annotation to MAVEN mode enum value - Replace broken loadFromMaven() with UnsupportedOperationException - Document searchInJars() is completely non-functional - Update README to note MAVEN mode is deprecated - Direct users to use MavenNexusClassSource instead searchInJars() has backwards logic (returns null on success), swallows all exceptions, and never actually searches JAR files. Fixing it would require full JSON parsing of Nexus Search API - significant work. MavenNexusClassSource already provides complete, working implementation. Fixes #57 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent da50083 commit ada8496

2 files changed

Lines changed: 42 additions & 39 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ JClassLoader authLoader = JClassLoader.builder()
138138

139139
#### Loading from Nexus Maven Repository
140140

141+
**Note:** Use `MavenNexusClassSource` for loading classes from Maven artifacts in Nexus. The `NexusClassSource` MAVEN mode is deprecated and non-functional.
142+
141143
Load classes from JAR files stored as Maven artifacts:
142144

143145
```java

src/main/java/org/flossware/classloader/NexusClassSource.java

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ public class NexusClassSource implements ClassSource {
3232

3333
/**
3434
* Nexus repository mode.
35+
*
36+
* <p><b>WARNING:</b> MAVEN mode is currently non-functional due to incomplete
37+
* implementation of searchInJars(). Use MavenNexusClassSource instead for loading
38+
* classes from Maven artifacts in Nexus, or use RAW mode for direct .class files.</p>
3539
*/
3640
public enum NexusMode {
3741
/** Raw repository with direct .class files */
3842
RAW,
39-
/** Maven repository with JAR files */
43+
/**
44+
* Maven repository with JAR files.
45+
* @deprecated MAVEN mode is non-functional. Use {@link MavenNexusClassSource} instead.
46+
*/
47+
@Deprecated
4048
MAVEN
4149
}
4250

@@ -109,48 +117,41 @@ private byte[] loadFromRaw(String className) throws IOException {
109117
return fetchUrl(url);
110118
}
111119

120+
/**
121+
* @deprecated MAVEN mode is non-functional. searchInJars() is broken.
122+
* Use {@link MavenNexusClassSource} instead.
123+
*/
124+
@Deprecated
112125
private byte[] loadFromMaven(String className) throws IOException {
113-
String packagePath = getPackagePath(className);
114-
if (packagePath == null) {
115-
throw new IOException("Cannot determine Maven coordinates for class: " + className);
116-
}
117-
118-
String cachedKey = packagePath;
119-
// Atomic get() - avoids TOCTOU race condition with contains() + get()
120-
byte[] cachedData = jarCache.get(cachedKey);
121-
if (cachedData != null) {
122-
return cachedData;
123-
}
124-
125-
String simpleClassName = getSimpleClassName(className);
126-
String classFileInJar = ClassNameUtil.toClassFilePath(className);
127-
128-
byte[] classData = searchInJars(packagePath, classFileInJar);
129-
if (classData != null) {
130-
jarCache.put(cachedKey, classData);
131-
return classData;
132-
}
133-
134-
throw new IOException("Class not found in Nexus Maven repository: " + className);
126+
throw new UnsupportedOperationException(
127+
"MAVEN mode is non-functional (searchInJars() not implemented). " +
128+
"Use MavenNexusClassSource instead for loading classes from Maven artifacts in Nexus."
129+
);
135130
}
136131

132+
/**
133+
* @deprecated This method is non-functional (returns null always).
134+
* Proper implementation would require JSON parsing of Nexus search API response.
135+
*/
136+
@Deprecated
137+
@SuppressWarnings("unused")
137138
private byte[] searchInJars(String packagePath, String classFileInJar) throws IOException {
138-
String searchUrl = nexusUrl + "service/rest/v1/search?repository=" + repository + "&name=" + packagePath;
139-
140-
try {
141-
URL url = new URL(searchUrl);
142-
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
143-
configureAuthentication(connection);
144-
connection.setRequestMethod("GET");
145-
146-
int responseCode = connection.getResponseCode();
147-
if (responseCode == HttpURLConnection.HTTP_OK) {
148-
return null;
149-
}
150-
} catch (IOException e) {
151-
}
152-
153-
return null;
139+
// This method is completely broken:
140+
// 1. Returns null when HTTP 200 OK (backwards logic!)
141+
// 2. Swallows all exceptions
142+
// 3. Never actually parses the response or downloads JARs
143+
// 4. Always returns null
144+
//
145+
// Proper implementation would require:
146+
// - Parse Nexus search API JSON response
147+
// - Extract JAR download URLs
148+
// - Download each JAR and search for the class
149+
// - Return class bytecode
150+
//
151+
// Use MavenNexusClassSource instead - it's a complete implementation.
152+
throw new UnsupportedOperationException(
153+
"searchInJars() is not implemented. Use MavenNexusClassSource instead."
154+
);
154155
}
155156

156157
private byte[] fetchUrl(String urlString) throws IOException {

0 commit comments

Comments
 (0)