Skip to content

Commit

Permalink
Fix PMD UnnecessaryFullyQualifiedName
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed May 24, 2024
1 parent 8123ea7 commit 1c8678a
Show file tree
Hide file tree
Showing 34 changed files with 53 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="1.27.0" date="YYYY-MM-DD" description="This is a feature and maintenance release. Java 8 or later is required.">
<!-- FIX -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Fix PMD UnnecessaryFullyQualifiedName.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ArchiveInputStream.forEach(IOConsumer).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ArchiveInputStream.iterator().</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public enum PERMISSION {
public static Set<PERMISSION> find(final int code) {
final Set<PERMISSION> set = new HashSet<>();

for (final PERMISSION p : PERMISSION.values()) {
for (final PERMISSION p : values()) {
if ((code & p.code) == p.code) {
set.add(p);
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public enum TYPE {
public static TYPE find(final int code) {
TYPE type = UNKNOWN;

for (final TYPE t : TYPE.values()) {
for (final TYPE t : values()) {
if (code == t.code) {
type = t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ final class DumpArchiveUtil {
public static int calculateChecksum(final byte[] buffer) {
int calc = 0;
for (int i = 0; i < 256; i++) {
calc += DumpArchiveUtil.convert32(buffer, 4 * i);
calc += convert32(buffer, 4 * i);
}
return DumpArchiveConstants.CHECKSUM - (calc - DumpArchiveUtil.convert32(buffer, 28));
return DumpArchiveConstants.CHECKSUM - (calc - convert32(buffer, 28));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private static String normalizeFileName(String fileName, final boolean preserveA

private static Instant parseInstantFromDecimalSeconds(final String value) throws IOException {
// Validate field values to prevent denial of service attacks with BigDecimal values (see JDK-6560193)
if (!TarArchiveEntry.PAX_EXTENDED_HEADER_FILE_TIMES_PATTERN.matcher(value).matches()) {
if (!PAX_EXTENDED_HEADER_FILE_TIMES_PATTERN.matcher(value).matches()) {
throw new IOException("Corrupted PAX header. Time field value is invalid '" + value + "'");
}

Expand Down Expand Up @@ -382,7 +382,7 @@ private static Instant parseInstantFromDecimalSeconds(final String value) throws
/** Extra, user supplied pax headers */
private final Map<String, String> extraPaxHeaders = new HashMap<>();

private long dataOffset = EntryStreamOffsets.OFFSET_UNKNOWN;
private long dataOffset = OFFSET_UNKNOWN;

/**
* Constructs an empty entry and prepares the header values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
*
* @NotThreadSafe
*/
public class ZipArchiveEntry extends java.util.zip.ZipEntry implements ArchiveEntry, EntryStreamOffsets {
public class ZipArchiveEntry extends ZipEntry implements ArchiveEntry, EntryStreamOffsets {

/**
* Indicates how the comment of this entry has been determined.
Expand Down Expand Up @@ -251,7 +251,7 @@ private static String toEntryName(final Path inputPath, final String entryName,
}

/**
* The {@link java.util.zip.ZipEntry} base class only supports the compression methods STORED and DEFLATED. We override the field so that any compression
* The {@link ZipEntry} base class only supports the compression methods STORED and DEFLATED. We override the field so that any compression
* methods can be used.
* <p>
* The default value -1 means that the method has not been specified.
Expand All @@ -261,7 +261,7 @@ private static String toEntryName(final Path inputPath, final String entryName,
private int method = ZipMethod.UNKNOWN_CODE;

/**
* The {@link java.util.zip.ZipEntry#setSize} method in the base class throws an IllegalArgumentException if the size is bigger than 2GB for Java versions
* The {@link ZipEntry#setSize} method in the base class throws an IllegalArgumentException if the size is bigger than 2GB for Java versions
* &lt; 7 and even in Java 7+ if the implementation in java.util.zip doesn't support Zip64 itself (it is an optional feature).
* <p>
* We need to keep our own size information for Zip64 support.
Expand Down Expand Up @@ -352,7 +352,7 @@ private ZipArchiveEntry(final Function<ZipShort, ZipExtraField> extraFieldFactor
* @param entry the entry to get fields from
* @throws ZipException on error
*/
private ZipArchiveEntry(final Function<ZipShort, ZipExtraField> extraFieldFactory, final java.util.zip.ZipEntry entry) throws ZipException {
private ZipArchiveEntry(final Function<ZipShort, ZipExtraField> extraFieldFactory, final ZipEntry entry) throws ZipException {
super(entry);
this.extraFieldFactory = extraFieldFactory;
setName(entry.getName());
Expand Down Expand Up @@ -413,7 +413,7 @@ private ZipArchiveEntry(final Function<ZipShort, ZipExtraField> extraFieldFactor
* @param entry the entry to get fields from
* @throws ZipException on error
*/
public ZipArchiveEntry(final java.util.zip.ZipEntry entry) throws ZipException {
public ZipArchiveEntry(final ZipEntry entry) throws ZipException {
this(null, entry);
}

Expand Down Expand Up @@ -460,7 +460,7 @@ public ZipArchiveEntry(final String name) {
* @throws ZipException on error
*/
public ZipArchiveEntry(final ZipArchiveEntry entry) throws ZipException {
this((java.util.zip.ZipEntry) entry);
this((ZipEntry) entry);
setInternalAttributes(entry.getInternalAttributes());
setExternalAttributes(entry.getExternalAttributes());
setExtraFields(entry.getAllExtraFieldsNoCopy());
Expand Down Expand Up @@ -779,10 +779,10 @@ public int getInternalAttributes() {
}

/**
* Wraps {@link java.util.zip.ZipEntry#getTime} with a {@link Date} as the entry's last modified date.
* Wraps {@link ZipEntry#getTime} with a {@link Date} as the entry's last modified date.
*
* <p>
* Changes to the implementation of {@link java.util.zip.ZipEntry#getTime} leak through and the returned value may depend on your local time zone as well as
* Changes to the implementation of {@link ZipEntry#getTime()} leak through and the returned value may depend on your local time zone as well as
* your version of Java.
* </p>
*/
Expand Down Expand Up @@ -1519,7 +1519,7 @@ private void updateTimeFieldsFromExtraFields() {
}

/**
* Workaround for the fact that, as of Java 17, {@link java.util.zip.ZipEntry} does not properly modify the entry's {@code xdostime} field, only setting
* Workaround for the fact that, as of Java 17, {@link ZipEntry} does not properly modify the entry's {@code xdostime} field, only setting
* {@code mtime}. While this is not strictly necessary, it's better to maintain the same behavior between this and the NTFS field.
*/
private void updateTimeFromExtendedTimestampField() {
Expand Down Expand Up @@ -1548,7 +1548,7 @@ private void updateTimeFromExtendedTimestampField() {
}

/**
* Workaround for the fact that, as of Java 17, {@link java.util.zip.ZipEntry} parses NTFS timestamps with a maximum precision of microseconds, which is
* Workaround for the fact that, as of Java 17, {@link ZipEntry} parses NTFS timestamps with a maximum precision of microseconds, which is
* lower than the 100ns precision provided by this extra field.
*/
private void updateTimeFromNtfsField() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public ZipEightByteInteger(final byte[] bytes) {
* @param offset the offset to start
*/
public ZipEightByteInteger(final byte[] bytes, final int offset) {
value = ZipEightByteInteger.getValue(bytes, offset);
value = getValue(bytes, offset);
}

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ public boolean equals(final Object o) {
* @return value as eight bytes in big-endian order
*/
public byte[] getBytes() {
return ZipEightByteInteger.getBytes(value);
return getBytes(value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;

import org.apache.commons.io.Charsets;
Expand All @@ -34,7 +33,7 @@ public abstract class ZipEncodingHelper {
/**
* UTF-8.
*/
static final ZipEncoding ZIP_ENCODING_UTF_8 = getZipEncoding(StandardCharsets.UTF_8);
static final ZipEncoding ZIP_ENCODING_UTF_8 = getZipEncoding(UTF_8);

/**
* Instantiates a ZIP encoding. An NIO based character set encoder/decoder will be returned. As a special case, if the character set is UTF-8, the NIO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @Immutable
*/
public final class ZipLong implements Cloneable, Serializable {

private static final long serialVersionUID = 1L;

/** Central File Header Signature */
Expand Down Expand Up @@ -135,7 +136,7 @@ public ZipLong(final byte[] bytes) {
* @param offset the offset to start
*/
public ZipLong(final byte[] bytes, final int offset) {
value = ZipLong.getValue(bytes, offset);
value = getValue(bytes, offset);
}

/**
Expand Down Expand Up @@ -187,7 +188,7 @@ public boolean equals(final Object o) {
* @return value as four bytes in big-endian order
*/
public byte[] getBytes() {
return ZipLong.getBytes(value);
return getBytes(value);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public ZipShort(final byte[] bytes) {
* @param offset the offset to start
*/
public ZipShort(final byte[] bytes, final int offset) {
value = ZipShort.getValue(bytes, offset);
value = getValue(bytes, offset);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static BigInteger longToBig(long l) {
if (l < 0 && l >= Integer.MIN_VALUE) {
// If someone passes in a -2, they probably mean 4294967294
// (For example, UNIX UID/GID's are 32 bit unsigned.)
l = ZipUtil.adjustToLong((int) l);
l = adjustToLong((int) l);
}
return BigInteger.valueOf(l);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private static final class Data {
// ===============

Data(final int blockSize100k) {
this.ll8 = new byte[blockSize100k * BZip2Constants.BASEBLOCKSIZE];
this.ll8 = new byte[blockSize100k * BASEBLOCKSIZE];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static final class Data {
int origPtr;

Data(final int blockSize100k) {
final int n = blockSize100k * BZip2Constants.BASEBLOCKSIZE;
final int n = blockSize100k * BASEBLOCKSIZE;
this.block = new byte[n + 1 + NUM_OVERSHOOT_BYTES];
this.fmap = new int[n];
this.sfmap = new char[2 * n];
Expand Down Expand Up @@ -438,7 +438,7 @@ public BZip2CompressorOutputStream(final OutputStream out, final int blockSize)
this.out = out;

/* 20 is just a paranoia constant */
this.allowableBlockSize = this.blockSize100k * BZip2Constants.BASEBLOCKSIZE - 20;
this.allowableBlockSize = this.blockSize100k * BASEBLOCKSIZE - 20;
init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void pack(final JarFile file, final OutputStream out) throws IOException
}
completed(0);
try {
new org.apache.commons.compress.harmony.pack200.Archive(file, out, options).pack();
new Archive(file, out, options).pack();
} catch (final Pack200Exception e) {
throw new IOException("Failed to pack Jar:" + e);
}
Expand All @@ -92,7 +92,7 @@ public void pack(final JarInputStream in, final OutputStream out) throws IOExcep
final PackingOptions options = new PackingOptions();

try {
new org.apache.commons.compress.harmony.pack200.Archive(in, out, options).pack();
new Archive(in, out, options).pack();
} catch (final Pack200Exception e) {
throw new IOException("Failed to pack Jar:" + e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public int[] decodeInts(final int n, final InputStream in) throws IOException, P
// if tokenCodec needs to be derived from the T, L and K values
if (tokenCodec == null) {
if (k < 256) {
tokenCodec = Codec.BYTE1;
tokenCodec = BYTE1;
} else {
// if k >= 256, b >= 2
int b = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static ByteCode getByteCode(final int opcode) {
private int[] byteCodeTargets;

protected ByteCode(final int opcode) {
this(opcode, ClassFileEntry.NONE);
this(opcode, NONE);
}

protected ByteCode(final int opcode, final ClassFileEntry[] nested) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class CPClass extends ConstantPoolEntry {
* @throws NullPointerException if name is null
*/
public CPClass(final CPUTF8 name, final int globalIndex) {
super(ConstantPoolEntry.CP_Class, globalIndex);
super(CP_Class, globalIndex);
this.name = Objects.requireNonNull(name, "name").underlyingString();
this.utf8 = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class CPDouble extends CPConstantNumber {

public CPDouble(final Double value, final int globalIndex) {
super(ConstantPoolEntry.CP_Double, value, globalIndex);
super(CP_Double, value, globalIndex);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CPFieldRef extends ConstantPoolEntry {
private int cachedHashCode;

public CPFieldRef(final CPClass className, final CPNameAndType descriptor, final int globalIndex) {
super(ConstantPoolEntry.CP_Fieldref, globalIndex);
super(CP_Fieldref, globalIndex);
this.className = className;
this.nameAndType = descriptor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class CPFloat extends CPConstantNumber {

public CPFloat(final Float value, final int globalIndex) {
super(ConstantPoolEntry.CP_Float, value, globalIndex);
super(CP_Float, value, globalIndex);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class CPInteger extends CPConstantNumber {

public CPInteger(final Integer value, final int globalIndex) {
super(ConstantPoolEntry.CP_Integer, value, globalIndex);
super(CP_Integer, value, globalIndex);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CPInterfaceMethodRef extends CPRef {
private int cachedHashCode;

public CPInterfaceMethodRef(final CPClass className, final CPNameAndType descriptor, final int globalIndex) {
super(ConstantPoolEntry.CP_InterfaceMethodref, className, descriptor, globalIndex);
super(CP_InterfaceMethodref, className, descriptor, globalIndex);
}

private void generateHashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class CPLong extends CPConstantNumber {

public CPLong(final Long value, final int globalIndex) {
super(ConstantPoolEntry.CP_Long, value, globalIndex);
super(CP_Long, value, globalIndex);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CPMethodRef extends CPRef {
private int cachedHashCode;

public CPMethodRef(final CPClass className, final CPNameAndType descriptor, final int globalIndex) {
super(ConstantPoolEntry.CP_Methodref, className, descriptor, globalIndex);
super(CP_Methodref, className, descriptor, globalIndex);
}

private void generateHashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CPNameAndType extends ConstantPoolEntry {
* @throws NullPointerException if name or descriptor is null
*/
public CPNameAndType(final CPUTF8 name, final CPUTF8 descriptor, final int globalIndex) {
super(ConstantPoolEntry.CP_NameAndType, globalIndex);
super(CP_NameAndType, globalIndex);
this.name = Objects.requireNonNull(name, "name");
this.descriptor = Objects.requireNonNull(descriptor, "descriptor");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ protected void resolve(final ClassConstantPool pool) {
public String toString() {
if (cachedToString == null) {
String type;
if (getTag() == ConstantPoolEntry.CP_Fieldref) {
if (getTag() == CP_Fieldref) {
type = "FieldRef"; //$NON-NLS-1$
} else if (getTag() == ConstantPoolEntry.CP_Methodref) {
} else if (getTag() == CP_Methodref) {
type = "MethoddRef"; //$NON-NLS-1$
} else if (getTag() == ConstantPoolEntry.CP_InterfaceMethodref) {
} else if (getTag() == CP_InterfaceMethodref) {
type = "InterfaceMethodRef"; //$NON-NLS-1$
} else {
type = "unknown"; //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class CPString extends CPConstant {
private int cachedHashCode;

public CPString(final CPUTF8 value, final int globalIndex) {
super(ConstantPoolEntry.CP_String, value, globalIndex);
super(CP_String, value, globalIndex);
this.name = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CPUTF8(final String string) {
* @throws NullPointerException if utf8 is null
*/
public CPUTF8(final String utf8, final int globalIndex) {
super(ConstantPoolEntry.CP_UTF8, globalIndex);
super(CP_UTF8, globalIndex);
this.utf8 = Objects.requireNonNull(utf8, "utf8");
}

Expand Down
Loading

0 comments on commit 1c8678a

Please sign in to comment.