From 084e1413e1a8eecacc3a7652976a10e8f7933c5b Mon Sep 17 00:00:00 2001 From: "sonarqube-agent[bot]" <210722872+sonarqube-agent[bot]@users.noreply.github.com> Date: Tue, 31 Mar 2026 03:29:02 +0000 Subject: [PATCH] fix: Address SonarQube issue Fixed issues: - AZZmtiWq2HDYqP_XyoAv for java:S2112 rule Generated by SonarQube Agent (task: e50b25ec-9b82-4ec6-a218-cbbdece5e6b7) --- .../com/webcohesion/enunciate/Enunciate.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/webcohesion/enunciate/Enunciate.java b/core/src/main/java/com/webcohesion/enunciate/Enunciate.java index 729642b4d..6cfe06fa0 100644 --- a/core/src/main/java/com/webcohesion/enunciate/Enunciate.java +++ b/core/src/main/java/com/webcohesion/enunciate/Enunciate.java @@ -585,7 +585,7 @@ public void run() { getLogger().debug("Detected API Types: %s", new EnunciateLogger.ListWriter(includedTypes)); //gather all the java source files. - Set sourceFiles = getSourceFileURLs(); + Set sourceFiles = getSourceFileURLs(); URLClassLoader apiClassLoader = new URLClassLoader(scanpath.toArray(new URL[0])); for (String javaFile : scannedSourceFiles) { @@ -602,7 +602,11 @@ public void run() { } else { URL resource = resources.nextElement(); if (!resources.hasMoreElements()) { - sourceFiles.add(resource); + try { + sourceFiles.add(resource.toURI()); + } catch (URISyntaxException e) { + throw new EnunciateException(e); + } } else { StringBuilder locations = new StringBuilder("[").append(resource.toString()); while (resources.hasMoreElements()) { @@ -616,7 +620,11 @@ public void run() { if (sourceFiles.isEmpty()) { //Java compiler needs _something_ to compile, so we'll provide an dummy class. - sourceFiles.add(Enunciate.class.getResource("/com/webcohesion/enunciate/Nothing.java")); + try { + sourceFiles.add(Enunciate.class.getResource("/com/webcohesion/enunciate/Nothing.java").toURI()); + } catch (URISyntaxException e) { + throw new EnunciateException(e); + } } //invoke the processor. @@ -643,8 +651,12 @@ public void run() { getLogger().debug("Compiler sources: %s", new EnunciateLogger.ListWriter(sourceFiles)); List sources = new ArrayList<>(sourceFiles.size()); String encoding = findEncoding(compilerArgs); - for (URL sourceFile : sourceFiles) { - sources.add(new URLFileObject(sourceFile, encoding)); + for (URI sourceFile : sourceFiles) { + try { + sources.add(new URLFileObject(sourceFile.toURL(), encoding)); + } catch (MalformedURLException e) { + throw new EnunciateException(e); + } } JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); @@ -771,14 +783,10 @@ public String writeClasspath(List cp) { return builder.toString(); } - protected Set getSourceFileURLs() { - Set sourceFiles = new HashSet<>(this.sourceFiles.size()); + protected Set getSourceFileURLs() { + Set sourceFiles = new HashSet<>(this.sourceFiles.size()); for (File sourceFile : this.sourceFiles) { - try { - sourceFiles.add(sourceFile.toURI().toURL()); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } + sourceFiles.add(sourceFile.toURI()); } return sourceFiles; }