Skip to content

Commit

Permalink
first bunch of PMD fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mprins committed Apr 25, 2024
1 parent ddac9a9 commit 7636d7f
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/ows/src/main/java/org/geoserver/ows/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ else if (parameterType.isAssignableFrom(InputStream.class)) {
boolean kvpParsed = false;
boolean xmlParsed = false;

if (req.getKvp() != null && req.getKvp().size() > 0) {
if (req.getKvp() != null && !req.getKvp().isEmpty()) {
// use the kvp reader mechanism
try {
requestBean = parseRequestKVP(parameterType, req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public void finished(Request request) {
List<FileItem> items = FILE_ITEMS.get();
FILE_ITEMS.remove();
if (!items.isEmpty()) {
try (Reader r = request.getInput()) {
//noinspection EmptyTryBlock
try (Reader ignored = request.getInput()) {
// just closing the input which may be pointing to a temp file
} catch (Exception e) {
LOGGER.log(Level.FINEST, "Unable to close request input", e);
Expand Down
2 changes: 1 addition & 1 deletion src/ows/src/main/java/org/geoserver/ows/URLMangler.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public enum URLType {
RESOURCE,
/** The link points to a dynamic service provided by Geoserver (WFS, WMS, WCS, etc.) */
SERVICE
};
}

/**
* Callback that can change the contents of the baseURL, the path or the KVP map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public Collection parse(String value) throws ParseException {
return Collections.emptyList();
}
value = value.trim();
if (value.length() == 0) {
if (value.isEmpty()) {
return Collections.emptyList();
}
final Set values =
new TreeSet(
new TreeSet<>(
(o1, o2) -> {
final boolean o1Double = o1 instanceof Double;
final boolean o2Double = o2 instanceof Double;
Expand Down Expand Up @@ -138,7 +138,7 @@ public Collection parse(String value) throws ParseException {
checkMaxElevations(values, maxValues);
}

return new ArrayList(values);
return new ArrayList<>(values);
}

/** Maximum number of elevations this parser will parse before throwing an exception */
Expand Down
6 changes: 3 additions & 3 deletions src/ows/src/main/java/org/geoserver/ows/util/OwsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ public static void resolveCollections(Object object) {
}
if (value == null) {
if (Map.class.isAssignableFrom(type)) {
value = new HashMap();
value = new HashMap<>();
} else if (List.class.isAssignableFrom(type)) {
value = new ArrayList();
value = new ArrayList<>();
} else if (Set.class.isAssignableFrom(type)) {
value = new HashSet();
value = new HashSet<>();
} else {
throw new RuntimeException("Unknown collection type:" + type.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static Reader getCharsetAwareReader(InputStream istream, EncodingInfo enc
encInfo.copyFrom(getEncodingName(b4, count));

if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Charset detection phase 1. Inferred encoding: " + encInfo.toString());
LOGGER.fine("Charset detection phase 1. Inferred encoding: " + encInfo);
}

// Rewinding to beginning of data
Expand Down Expand Up @@ -182,7 +182,7 @@ public static Reader getCharsetAwareReader(InputStream istream, EncodingInfo enc
*/
if ("ISO-10646-UCS-4".equals(ENCODING)) {
if (null != isBigEndian) {
boolean isBE = isBigEndian.booleanValue();
boolean isBE = isBigEndian;

if (isBE) {
reader = new UCSReader(stream, UCSReader.UCS4BE);
Expand Down Expand Up @@ -301,7 +301,7 @@ public static Reader createReader(InputStream istream, EncodingInfo encInfo)
// UCS-2|4 charsets are handled with custom reader
if ("ISO-10646-UCS-4".equals(charset)) {
if (null != isBigEndian) {
boolean isBE = isBigEndian.booleanValue();
boolean isBE = isBigEndian;

if (isBE) {
reader = new UCSReader(istream, UCSReader.UCS4BE);
Expand All @@ -315,7 +315,7 @@ public static Reader createReader(InputStream istream, EncodingInfo encInfo)
}
} else if ("ISO-10646-UCS-2".equals(charset)) {
if (null != isBigEndian) {
boolean isBE = isBigEndian.booleanValue();
boolean isBE = isBigEndian;

if (isBE) {
reader = new UCSReader(istream, UCSReader.UCS4BE);
Expand Down Expand Up @@ -463,7 +463,7 @@ protected static String getXmlEncoding(Reader reader) {
*/
if ((6 > count) || (!"<?xml ".equals(sw.toString()))) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("Invalid(?) XML declaration: " + sw.toString() + ".");
LOGGER.finer("Invalid(?) XML declaration: " + sw + ".");
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @author Simone Giannecchini, GeoSolutions SAS
* @author Jonathan Meyer, Applied Information Sciences, jon@gisjedi.com
*/
@SuppressWarnings({"rawtypes", "PMD.UseDiamondOperator"})
public class TimeKvpParserTest {
/** A time period for testing. */
private static final String PERIOD = "2007-01-01T12Z/2007-01-31T12Z/P1DT12H";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ public void testPut() throws Exception {
try {
OwsUtils.put(baz, "map", "k", "v");
Assert.fail("null map should cause exception");
} catch (NullPointerException e) {
} catch (NullPointerException ignored) {
// ignore
}

baz.map = new HashMap();
baz.map = new HashMap<>();
try {
OwsUtils.put(baz, "xyz", "k", "v");
Assert.fail("bad property should cause exception");
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException ignored) {
// ignore
}

Assert.assertTrue(baz.map.isEmpty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private FileWatcher<Properties> loadGeoServerEnvProps(String propertyFile) {
}

private FileWatcher<Properties> loadGeoServerEnvProps(Resource propertyFile) {
return new FileWatcher<Properties>(propertyFile) {
return new FileWatcher<>(propertyFile) {

@Override
protected Properties parseFileContents(InputStream in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,7 @@ public static String lookupGeoServerDataDirectory(ServletContext servContext) {
* @param source description of source from which file name(s) obtained
*/
static void requireFile(String files, String source) {
if (files == null || files.isEmpty()) {
return;
} else {
if (files != null && !files.isEmpty()) {
for (String file : files.split(File.pathSeparator)) {
if (!(new File(file)).exists()) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public static class DirectoryFilter implements Filter<Resource> {

public static final DirectoryFilter INSTANCE = new DirectoryFilter();

private DirectoryFilter() {};
private DirectoryFilter() {}

@Override
public boolean accept(Resource obj) {
Expand All @@ -469,7 +469,7 @@ public static class AnyFilter implements Filter<Resource> {

public static final AnyFilter INSTANCE = new AnyFilter();

private AnyFilter() {};
private AnyFilter() {}

@Override
public boolean accept(Resource obj) {
Expand Down
10 changes: 5 additions & 5 deletions src/platform/src/main/java/org/geoserver/util/ReaderUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static File checkFile(File file, boolean isDir) throws FileNotFoundExcept
}

if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("File is valid: ").append(file).toString());
LOGGER.finer("File is valid: " + file);
}

return file;
Expand Down Expand Up @@ -237,7 +237,7 @@ public static Element getChildElement(Element root, String name) {
* @param defaultValue a default value to return incase the attribute was not found. mutually
* exclusive with the Exception thrown.
* @return The int value if the attribute was found, the default otherwise.
* @throws Exception When a attribute element is required and not found.
* @throws Exception When an attribute element is required and not found.
*/
public static int getIntAttribute(
Element elem, String attName, boolean mandatory, int defaultValue) throws Exception {
Expand Down Expand Up @@ -415,7 +415,7 @@ public static String getElementText(Element elem, boolean mandatory) throws Exce
String value = null;

if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("getting element text for ").append(elem).toString());
LOGGER.finer("getting element text for " + elem);
}

if (elem != null) {
Expand Down Expand Up @@ -479,7 +479,7 @@ public static List getKeyWords(Element keywordsElem) {
Object[] s = keywords.toArray();

if (s == null) {
return new ArrayList();
return new ArrayList<>();
}

List<Object> ss = new ArrayList<>(s.length);
Expand Down Expand Up @@ -522,7 +522,7 @@ public static Element getFirstChildElement(Element root) {
* @param mandatory true when an exception should be thrown if the attribute element does not
* exist.
* @return The double value if the attribute was found, the NaN otherwise.
* @throws Exception When a attribute element is required and not found.
* @throws Exception When an attribute element is required and not found.
*/
public static double getDoubleAttribute(Element elem, String attName, boolean mandatory)
throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GeoServerPropertyFactoryBeanTest {
@Before
public void setUp() {
factory =
new GeoServerPropertyFactoryBean<String>(PROPERTY_NAME) {
new GeoServerPropertyFactoryBean<>(PROPERTY_NAME) {

@Override
protected String createInstance(String propertyValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Matcher<Document> hasNode(final String xPath) {
*/
public Matcher<Document> hasNodes(
final String xPath, final Matcher<? extends Iterable<Node>> matcher) {
return new BaseMatcher<Document>() {
return new BaseMatcher<>() {

@Override
public boolean matches(Object item) {
Expand Down Expand Up @@ -139,7 +139,7 @@ public void describeMismatch(Object item, Description description) {

/** Make a Java List out of a DOM NodeList. */
public static List<Node> nodeCollection(final NodeList nl) {
return new AbstractList<Node>() {
return new AbstractList<>() {

@Override
public Node get(int index) {
Expand Down

0 comments on commit 7636d7f

Please sign in to comment.