wenjin272 opened a new issue, #966: URL: https://github.com/apache/flink-agents/issues/966
### Search before asking - [x] I searched the [issues](https://github.com/apache/flink-agents/issues) and found nothing similar. ### Description `ClasspathSkillRepository` fails to load skills when a classloader exposes an application JAR through a relative local URL, for example: ```text jar:file:../../flink/usrlib/job.jar!/diagnosis-skills ``` This URL form can be produced when a Flink deployment adds user-code JARs relative to the TaskManager working directory. `SkillMaterializer.copyJarEntries()` extracts the inner URL (`file:../../flink/usrlib/job.jar`), converts it to a `URI`, and passes it to `new File(URI)`. The relative `file:` URI is opaque rather than hierarchical, so `File(URI)` throws `IllegalArgumentException: URI is not hierarchical`. The exception is wrapped as an invalid JAR URL and skill initialization fails. A representative stack trace is: ```text java.lang.IllegalStateException: Failed to load skills from classpath:{resource=diagnosis-skills} at org.apache.flink.agents.runtime.skill.SkillManager.loadAll(SkillManager.java:191) Caused by: java.io.IOException: Invalid JAR URL: jar:file:../../flink/usrlib/job.jar!/diagnosis-skills at org.apache.flink.agents.runtime.skill.repository.SkillMaterializer.copyJarEntries(SkillMaterializer.java:212) at org.apache.flink.agents.runtime.skill.repository.SkillMaterializer.extractClasspathFromJars(SkillMaterializer.java:183) at org.apache.flink.agents.runtime.skill.repository.ClasspathSkillRepository.materialize(ClasspathSkillRepository.java:132) Caused by: java.lang.IllegalArgumentException: URI is not hierarchical at java.io.File.<init>(File.java:420) at org.apache.flink.agents.runtime.skill.repository.SkillMaterializer.copyJarEntries(SkillMaterializer.java:207) ``` The same assumption also exists in the `URLClassLoader#getURLs()` fallback scan in `ClasspathSkillRepository.findAllMatches()`, so a relative `file:` JAR URL can be skipped or fail before the resource is materialized. Direct relative `file:` directory resources are affected by the corresponding `Paths.get(url.toURI())` conversion as well. Expected behavior: local relative `file:` URLs should be resolved relative to the process working directory and classpath skills should load normally. Absolute hierarchical `file:` URLs should keep their current behavior, while unsupported non-file URLs should be rejected or skipped explicitly. One possible implementation direction is to centralize local URL conversion: - accept only the `file` protocol; - use `new File(uri)` for hierarchical file URIs; - for an opaque relative file URI, use its decoded scheme-specific part as the relative path; - reuse the conversion in direct resource materialization, JAR extraction, and fallback classpath scanning. ### How to reproduce 1. Create a JAR containing `diagnosis-skills/example/SKILL.md`. 2. Add the JAR to a `URLClassLoader` using a relative URL such as `file:../../flink/usrlib/job.jar`, or make `getResources("diagnosis-skills")` return `jar:file:../../flink/usrlib/job.jar!/diagnosis-skills`. 3. Construct `ClasspathSkillRepository` for the `diagnosis-skills` resource, directly or through `SkillManager`. 4. Observe that repository initialization fails with `IllegalArgumentException: URI is not hierarchical`. The failure can also be reproduced in a unit test by creating a temporary skill JAR, relativizing its path against the current working directory, and constructing the URL with `new URL("file:" + relativePath)`. ### Version and environment - Apache Flink Agents: current `main` (the affected conversions are present in `SkillMaterializer` and `ClasspathSkillRepository`) - Apache Flink: 1.20-based distribution - Deployment mode: application/user-code JAR loaded from Flink's `usrlib` directory through a relative classpath URL - Java: 11 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
