Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating PMD to 7.2.0 #1279

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void testBundleFileResourceV2() throws Exception {
}

private boolean startsWithJPEGHeader(File f) {
try (FileInputStream fis = new FileInputStream(f); ) {
try (FileInputStream fis = new FileInputStream(f)) {

byte[] fileHeader = new byte[JFIFHeader.length];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public ConveyorTile doNonMetatilingRequest(ConveyorTile tile)

@Override
protected Matcher<TileLayer> infoEquals(TileLayer expected) {
return new CustomMatcher<TileLayer>(
return new CustomMatcher<>(
"ArcGISCacheLayer matching "
+ expected.getName()
+ " with "
Expand All @@ -140,7 +140,7 @@ public boolean matches(Object item) {

@Override
protected Matcher<TileLayer> infoEquals(int expected) {
return new CustomMatcher<TileLayer>("ArcGISCacheLayer with value" + expected) {
return new CustomMatcher<>("ArcGISCacheLayer with value" + expected) {

@Override
public boolean matches(Object item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public boolean delete(TileRange tileRange) throws StorageException {

// open an iterator oer tile locations, to avoid memory accumulation
final Iterator<long[]> tileLocations =
new AbstractIterator<long[]>() {
new AbstractIterator<>() {

// TileRange iterator with 1x1 meta tiling factor
private TileRangeIterator trIter =
Expand Down Expand Up @@ -405,7 +405,7 @@ public boolean removeListener(BlobStoreListener listener) {
@Override
public boolean rename(String oldLayerName, String newLayerName) throws StorageException {
log.fine("No need to rename layers, AzureBlobStore uses layer id as key root");
if (client.listBlobs(oldLayerName, 1).size() > 0) {
if (!client.listBlobs(oldLayerName, 1).isEmpty()) {
listeners.sendLayerRenamed(oldLayerName, newLayerName);
}
return true;
Expand Down Expand Up @@ -443,7 +443,7 @@ private Properties getLayerMetadata(String layerName) {
@Override
public boolean layerExists(String layerName) {
final String coordsPrefix = keyBuilder.forLayer(layerName);
return client.listBlobs(coordsPrefix, 1).size() > 0;
return !client.listBlobs(coordsPrefix, 1).isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void issuePendingBulkDeletes() throws StorageException {

public synchronized boolean asyncDelete(String prefix, long timestamp) {
// do we have anything to delete?
if (client.listBlobs(prefix, 1).size() == 0) {
if (client.listBlobs(prefix, 1).isEmpty()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public DefaultGridsets(boolean useEPSG900913, boolean useGWC11xNames) {
266.144470692553,
133.072235346276,
66.5361176731382,
33.2680588365691,
33.2680588365691
};

// the 60 UTM zones from the OGC TMS specification
Expand All @@ -441,32 +441,7 @@ public DefaultGridsets(boolean useEPSG900913, boolean useGWC11xNames) {
20003931.4586255),
true,
null,
new double[] {
279072704.500914,
139536352.250457,
69768176.1252285,
34884088.0626143,
17442044.0313071,
8721022.01565356,
4360511.00782678,
2180255.50391339,
1090127.7519567,
545063.875978348,
272531.937989174,
136265.968994587,
68132.9844972935,
34066.4922486467,
17033.2461243234,
8516.62306216168,
4258.31153108084,
2129.15576554042,
1064.57788277021,
532.288941385105,
266.144470692553,
133.072235346276,
66.5361176731382,
33.2680588365691
},
UTM_SCALES,
1d,
GridSetFactory.DEFAULT_PIXEL_SIZE_METER,
new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static enum PathGeneratorType {
DEFAULT,
TMS,
SLIPPY
};
}

private static final long serialVersionUID = -6470560864068854508L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ static void validate(Node rootNode) throws SAXException, IOException {
static String getCurrentSchemaVersion() {

Document dom;
try (InputStream is = XMLConfiguration.class.getResourceAsStream("geowebcache.xsd"); ) {
try (InputStream is = XMLConfiguration.class.getResourceAsStream("geowebcache.xsd")) {
dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private File findOrCreateConfFile() throws IOException {
// grab template from classpath
try {
try (InputStream templateStream = getClass().getResourceAsStream(templateLocation);
OutputStream output = new FileOutputStream(xmlFile); ) {
OutputStream output = new FileOutputStream(xmlFile)) {
IOUtils.copy(templateStream, output);
output.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public abstract class Conveyor {
public static enum RequestHandler {
LAYER,
SERVICE
};
}

public static enum CacheResult {
HIT,
MISS,
WMS,
OTHER
};
}

private String layerId = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void saveMatrix(byte[] data, TileLayer layer, String gridSetId, int zoomL
throws IOException {
// Persist
File fh = new File(createFilePath(gridSetId, zoomLevel));
try (FileOutputStream fos = new FileOutputStream(fh); ) {
try (FileOutputStream fos = new FileOutputStream(fh)) {
fos.write(data);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public GreenTileException(RequestFilter reqFilter) {
private Resource getGreenTile() {
byte[] green = new byte[659];

try (InputStream is = GreenTileException.class.getResourceAsStream("green.png"); ) {
try (InputStream is = GreenTileException.class.getResourceAsStream("green.png")) {
int ret = is.read(green);
log.info("Read " + ret + " from gree PNG file (expected 659).");
} catch (IOException ioe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,19 @@ public long getSize() {

/** @see org.geowebcache.io.Resource#transferTo(java.nio.channels.WritableByteChannel) */
@Override
@SuppressWarnings({"PMD.UnusedLocalVariable", "PMD.EmptyControlStatement"})
public long transferTo(WritableByteChannel channel) throws IOException {
if (length > 0) {
ByteBuffer buffer = ByteBuffer.wrap(data, offset, length);
long written = 0;
while ((written += channel.write(buffer)) < length) {;
}
while ((written += channel.write(buffer)) < length) ;
}
return length;
}

/** @see org.geowebcache.io.Resource#transferFrom(java.nio.channels.ReadableByteChannel) */
@Override
@SuppressWarnings({"PMD.UnusedLocalVariable", "PMD.EmptyControlStatement"})
public long transferFrom(ReadableByteChannel channel) throws IOException {
if (channel instanceof FileChannel) {
FileChannel fc = (FileChannel) channel;
Expand All @@ -114,8 +115,7 @@ public long transferFrom(ReadableByteChannel channel) throws IOException {
}
ByteBuffer buffer = ByteBuffer.wrap(data);
int read = 0;
while ((read += channel.read(buffer)) < length) {;
}
while ((read += channel.read(buffer)) < length) ;
} else {
offset = 0;
length = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,25 @@ public long getSize() {
}

@Override
@SuppressWarnings({"PMD.UnusedLocalVariable", "PMD.EmptyControlStatement"})
public long transferTo(WritableByteChannel target) throws IOException {
// FileLock lock = in.lock();

try (FileInputStream fis = new FileInputStream(file);
FileChannel in = fis.getChannel(); ) {
FileChannel in = fis.getChannel()) {
final long size = in.size();
long written = 0;
while ((written += in.transferTo(written, size, target)) < size) {;
}
while ((written += in.transferTo(written, size, target)) < size) ;
return size;
}
}

@Override
@SuppressWarnings("PMD.UnusedLocalVariable")
public long transferFrom(ReadableByteChannel channel) throws IOException {
try (FileOutputStream fos = new FileOutputStream(file);
FileChannel out = fos.getChannel();
FileLock lock = out.lock(); ) {
FileLock lock = out.lock()) {
final int buffsize = 4096;
long position = 0;
long read;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
reader.moveUp();
}
populateCollection(reader, context, result, set);
if (set.size() > 0) {
if (!set.isEmpty()) {
result.addAll(set); // comparator will not be called if internally optimized
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public boolean writeTileToStream(final int tileIdx, Resource target) throws IOEx
param = formatModifier.adjustImageWriteParam(param);
}
try (OutputStream outputStream = target.getOutputStream();
ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outputStream); ) {
ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outputStream)) {
writer.setOutput(imgOut);
IIOImage image = new IIOImage(tile, null, null);
writer.write(null, image, param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Iterable<TileLayer> getLayerListFiltered() {
Stream s =
StreamSupport.stream(result.spliterator(), false)
.filter(x -> !tileLayerDispatcherFilter.exclude(x));
result = (Iterable<TileLayer>) s::iterator;
result = s::iterator;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum GeometryType {
point,
line,
polygon
};
}

String id;
String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ public class WMSLayer extends AbstractTileLayer implements ProxyLayer {
public enum RequestType {
MAP,
FEATUREINFO
};
}

public enum HttpRequestMode {
Get,
FormPost;
FormPost
}

private String[] wmsUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ImageMime extends MimeType {
public boolean isCompatible(String otherMimeType) {
return super.isCompatible(otherMimeType)
|| otherMimeType.startsWith("image/png");
};
}
};

public static final ImageMime jpeg =
Expand Down Expand Up @@ -336,7 +336,7 @@ public String getMimeType(org.geowebcache.io.Resource resource) throws IOExcepti
return pngDelegate.getMimeType();
}
}
};
}

@Override
public boolean isCompatible(String otherMimeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public static enum TYPE {
SEED,
RESEED,
TRUNCATE
};
}

public static enum STATE {
UNSET,
READY,
RUNNING,
DONE,
DEAD
};
}

/**
* Value shared between all the threads in the group, is incremented each time a task starts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,9 @@ private void updateStatusInfo(TileLayer layer, long tilesCount, long start_time)
// estimated time of completion in seconds, use a moving average over the last
this.timeSpent = (int) (System.currentTimeMillis() - start_time) / 1000;

int threadCount = sharedThreadCount.get();
long timeTotal =
Math.round(
(double) timeSpent
* (((double) tilesTotal / threadCount) / (double) tilesCount));
// using double to force the next calcuation to double type
double threadCount = sharedThreadCount.get();
long timeTotal = Math.round(timeSpent * ((tilesTotal / threadCount) / tilesCount));

this.timeRemaining = (int) (timeTotal - timeSpent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static enum Status {
MISS,
LOCK,
EXPIRED_LOCK
};
}

Status status = Status.UNSET;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class TransientCache {
private static FilePathGenerator keyGenerator = new DefaultFilePathGenerator("");

private Map<String, CachedResource> cache =
new LinkedHashMap<String, CachedResource>() {
new LinkedHashMap<>() {

/** serialVersionUID */
private static final long serialVersionUID = -4106644240603796847L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
public interface TileFileVisitor {

/** Invoked before visitng a directory */
default void preVisitDirectory(File dir) {};
default void preVisitDirectory(File dir) {}

/** Invoked on a specific tile file */
public void visitFile(File tile, long x, long y, int z);

/** Invoked on a directory post file visit */
default void postVisitDirectory(File dir) {};
default void postVisitDirectory(File dir) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum Convention {
TMS,
/** Slippy map convention, where tile coordinates have their * origin at top left (NW) */
XYZ
};
}

@SuppressWarnings("unused")
private static Logger log = Logging.getLogger(XYZFilePathGenerator.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ private ExceptionUtils() {}
public static <T extends Throwable> boolean isOrSuppresses(T e, Class<? extends T> klazz) {
return Streams.concat(Stream.of(e), Arrays.stream(e.getSuppressed()))
.anyMatch(klazz::isInstance);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public static String[][] selectedStringArraysFromMap(
public static Map<String, String> selectedStringsFromMap(
Map<String, ?> map, String encoding, String... keys) {

map = new CaseInsensitiveMap(map);
Map<String, String> selected = new CaseInsensitiveMap();
map = new CaseInsensitiveMap<>(map);
Map<String, String> selected = new CaseInsensitiveMap<>();
for (String key : keys) {
Object value = map.get(key);
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static SeedRequest createRequest(
}

/** Matcher for an {@link HttpServletResponse} that checks its status. */
@SuppressWarnings("PMD.UseDiamondOperator")
public static Matcher<HttpServletResponse> hasStatus(HttpStatus expected) {
return new BaseMatcher<HttpServletResponse>() {

Expand Down
Loading
Loading