From 6cf47563fbfd14c6fa65f244b1b47160a467e6f6 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Wed, 28 May 2025 13:01:08 -0400 Subject: [PATCH] GP-0: Fixing warnings in Utility project --- .../src/main/java/generic/jar/JarResource.java | 16 ++++++++++------ .../framework/plugintool/ServiceProvider.java | 10 +++++----- .../Utility/src/main/java/ghidra/util/Fixup.java | 10 ++++------ .../java/ghidra/util/HashingOutputStream.java | 12 +++++++++--- .../main/java/ghidra/util/NullOutputStream.java | 5 +++++ .../java/ghidra/xml/AbstractXmlPullParser.java | 15 ++++++++++++--- 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/Ghidra/Framework/Utility/src/main/java/generic/jar/JarResource.java b/Ghidra/Framework/Utility/src/main/java/generic/jar/JarResource.java index b816f6750b..ff9d5e81a4 100644 --- a/Ghidra/Framework/Utility/src/main/java/generic/jar/JarResource.java +++ b/Ghidra/Framework/Utility/src/main/java/generic/jar/JarResource.java @@ -4,9 +4,9 @@ * Licensed 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 - * + * * http://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. @@ -15,14 +15,13 @@ */ package generic.jar; -import ghidra.util.Msg; -import ghidra.util.exception.AssertException; - import java.io.*; import java.net.*; import java.util.ArrayList; import java.util.List; +import ghidra.util.Msg; +import ghidra.util.exception.AssertException; import utilities.util.FileUtilities; import utility.application.ApplicationSettings; @@ -85,7 +84,12 @@ public class JarResource implements Resource { @Override public URL toURL() throws MalformedURLException { - return new URL(getAbsolutePath()); + try { + return new URI(getAbsolutePath()).toURL(); + } + catch (URISyntaxException e) { + throw new MalformedURLException(e.getMessage()); + } } @Override diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/plugintool/ServiceProvider.java b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/plugintool/ServiceProvider.java index 309bec022f..8281d170d4 100644 --- a/Ghidra/Framework/Utility/src/main/java/ghidra/framework/plugintool/ServiceProvider.java +++ b/Ghidra/Framework/Utility/src/main/java/ghidra/framework/plugintool/ServiceProvider.java @@ -1,13 +1,12 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed 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 - * + * * http://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. @@ -23,8 +22,9 @@ import ghidra.framework.plugintool.util.ServiceListener; */ public interface ServiceProvider { /** - * Returns the Service object that implements the given service interface. + * {@return the Service object that implements the given service interface.} * @param serviceClass the interface class. + * @param The type */ public T getService(Class serviceClass); @@ -39,7 +39,7 @@ public interface ServiceProvider { /** * Removes the given listener from this ServiceProvider. This method does nothing if the * given listener is not contained by this ServiceProvider. - * @param listener + * @param listener The listener to remove */ public void removeServiceListener( ServiceListener listener ); } diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/util/Fixup.java b/Ghidra/Framework/Utility/src/main/java/ghidra/util/Fixup.java index 2a830218ca..c15eb01db0 100644 --- a/Ghidra/Framework/Utility/src/main/java/ghidra/util/Fixup.java +++ b/Ghidra/Framework/Utility/src/main/java/ghidra/util/Fixup.java @@ -1,13 +1,12 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed 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 - * + * * http://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. @@ -29,9 +28,8 @@ public interface Fixup { public String getDescription(); /** - * Return true if this Fixup object can automatically perform some action to address the issue. false - * if the fixup() method does nothing. - * @return + * {@return true if this Fixup object can automatically perform some action to address the + * issue. false if the fixup() method does nothing.} */ public boolean canFixup(); diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/util/HashingOutputStream.java b/Ghidra/Framework/Utility/src/main/java/ghidra/util/HashingOutputStream.java index 453a94126c..a5d62eb792 100644 --- a/Ghidra/Framework/Utility/src/main/java/ghidra/util/HashingOutputStream.java +++ b/Ghidra/Framework/Utility/src/main/java/ghidra/util/HashingOutputStream.java @@ -4,9 +4,9 @@ * Licensed 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 - * + * * http://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. @@ -34,32 +34,38 @@ public class HashingOutputStream extends OutputStream { /** * @param out - OutputStream to wrap * @param hashAlgo - see {@link MessageDigest#getInstance(String)}, ie. "MD5". - * @throws NoSuchAlgorithmException + * @throws NoSuchAlgorithmException if no Provider supports a MessageDigestSpi implementation + * for the specified algorithm */ public HashingOutputStream(OutputStream out, String hashAlgo) throws NoSuchAlgorithmException { this.out = out; this.messageDigest = MessageDigest.getInstance(hashAlgo); } + @Override public void write(int b) throws IOException { messageDigest.update((byte) (b & 0xff)); out.write(b); } + @Override public void write(byte b[]) throws IOException { messageDigest.update(b); out.write(b, 0, b.length); } + @Override public void write(byte b[], int off, int len) throws IOException { messageDigest.update(b, off, len); out.write(b, off, len); } + @Override public void flush() throws IOException { out.flush(); } + @Override public void close() throws IOException { try (OutputStream ostream = out) { ostream.flush(); diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/util/NullOutputStream.java b/Ghidra/Framework/Utility/src/main/java/ghidra/util/NullOutputStream.java index 234ba2bb6f..af9b1a57d0 100644 --- a/Ghidra/Framework/Utility/src/main/java/ghidra/util/NullOutputStream.java +++ b/Ghidra/Framework/Utility/src/main/java/ghidra/util/NullOutputStream.java @@ -26,22 +26,27 @@ public class NullOutputStream extends OutputStream { public NullOutputStream() { } + @Override public void write(int b) throws IOException { // nada } + @Override public void write(byte b[]) throws IOException { // nada } + @Override public void write(byte b[], int off, int len) throws IOException { // nada } + @Override public void flush() throws IOException { // nada } + @Override public void close() throws IOException { // nada } diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/xml/AbstractXmlPullParser.java b/Ghidra/Framework/Utility/src/main/java/ghidra/xml/AbstractXmlPullParser.java index a5967be545..78dbee369b 100644 --- a/Ghidra/Framework/Utility/src/main/java/ghidra/xml/AbstractXmlPullParser.java +++ b/Ghidra/Framework/Utility/src/main/java/ghidra/xml/AbstractXmlPullParser.java @@ -1,13 +1,12 @@ /* ### * IP: GHIDRA - * REVIEWED: YES * * Licensed 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 - * + * * http://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. @@ -18,6 +17,7 @@ package ghidra.xml; public abstract class AbstractXmlPullParser implements XmlPullParser { + @Override public XmlElement end() { if (!hasNext()) { throw new XmlException("at EOF but expected end element"); @@ -30,6 +30,7 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { return next; } + @Override public XmlElement end(XmlElement element) { String name = element.getName(); if (!hasNext()) { @@ -47,6 +48,7 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { return next; } + @Override public int getColumnNumber() { if (hasNext()) { return peek().getColumnNumber(); @@ -54,6 +56,7 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { return -1; } + @Override public int getCurrentLevel() { if (hasNext()) { return peek().getLevel(); @@ -61,6 +64,7 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { return -1; } + @Override public int getLineNumber() { if (hasNext()) { return peek().getLineNumber(); @@ -86,6 +90,7 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { return sb.toString(); } + @Override public XmlElement start(String... names) { if (!hasNext()) { throw new XmlException("at EOF but expected start element " + collapse(names)); @@ -109,6 +114,7 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { return next; } + @Override public XmlElement softStart(String... names) { if (!hasNext()) { throw new XmlException("at EOF but expected soft start element " + collapse(names)); @@ -130,10 +136,12 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { return next(); } + @Override public int discardSubTree() { return discardSubTree(peek()); } + @Override public int discardSubTree(XmlElement element) { if (element == peek()) { // we're being asked to skip the entire subtree starting from the front of the queue @@ -193,6 +201,7 @@ public abstract class AbstractXmlPullParser implements XmlPullParser { } } + @Override public int discardSubTree(String elementName) { XmlElement start = start(elementName); return discardSubTree(start) + 1;