GP-0: Fixing warnings in Utility project

This commit is contained in:
Ryan Kurtz
2025-05-28 13:01:08 -04:00
parent b63f4d305b
commit 6cf47563fb
6 changed files with 45 additions and 23 deletions

View File

@@ -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

View File

@@ -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 <T> The type
*/
public <T> T getService(Class<T> 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 );
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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
}

View File

@@ -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;