Browse Source

SonarQube: unnecessary parentheses is a major code smell

master
Gintas Grigelionis 6 years ago
parent
commit
e2dd6ec79a
40 changed files with 104 additions and 141 deletions
  1. +3
    -4
      src/main/org/apache/tools/ant/AntTypeDefinition.java
  2. +3
    -3
      src/main/org/apache/tools/ant/ComponentHelper.java
  3. +5
    -5
      src/main/org/apache/tools/ant/Project.java
  4. +1
    -1
      src/main/org/apache/tools/ant/dispatch/DispatchUtils.java
  5. +6
    -10
      src/main/org/apache/tools/ant/listener/MailLogger.java
  6. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
  7. +3
    -3
      src/main/org/apache/tools/ant/taskdefs/Exit.java
  8. +3
    -4
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  9. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/JikesOutputParser.java
  10. +8
    -9
      src/main/org/apache/tools/ant/taskdefs/PreSetDef.java
  11. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Recorder.java
  12. +2
    -4
      src/main/org/apache/tools/ant/taskdefs/Redirector.java
  13. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/Touch.java
  14. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/condition/Os.java
  15. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java
  16. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
  17. +2
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
  18. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java
  19. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  20. +1
    -1
      src/main/org/apache/tools/ant/types/EnumeratedAttribute.java
  21. +1
    -2
      src/main/org/apache/tools/ant/types/Path.java
  22. +1
    -1
      src/main/org/apache/tools/ant/types/Permissions.java
  23. +3
    -4
      src/main/org/apache/tools/ant/types/RedirectorElement.java
  24. +4
    -4
      src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java
  25. +1
    -1
      src/main/org/apache/tools/ant/types/selectors/modifiedselector/EqualComparator.java
  26. +1
    -1
      src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java
  27. +1
    -1
      src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java
  28. +1
    -1
      src/main/org/apache/tools/ant/util/Base64Converter.java
  29. +1
    -1
      src/main/org/apache/tools/ant/util/DOMElementWriter.java
  30. +1
    -1
      src/main/org/apache/tools/ant/util/FileUtils.java
  31. +1
    -1
      src/main/org/apache/tools/bzip2/BZip2Constants.java
  32. +8
    -8
      src/main/org/apache/tools/bzip2/BlockSort.java
  33. +6
    -11
      src/main/org/apache/tools/bzip2/CBZip2OutputStream.java
  34. +15
    -27
      src/main/org/apache/tools/tar/TarBuffer.java
  35. +1
    -1
      src/main/org/apache/tools/tar/TarInputStream.java
  36. +1
    -1
      src/main/org/apache/tools/zip/ZipEightByteInteger.java
  37. +1
    -2
      src/main/org/apache/tools/zip/ZipFile.java
  38. +1
    -1
      src/main/org/apache/tools/zip/ZipLong.java
  39. +3
    -5
      src/main/org/apache/tools/zip/ZipOutputStream.java
  40. +1
    -1
      src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java

+ 3
- 4
src/main/org/apache/tools/ant/AntTypeDefinition.java View File

@@ -315,8 +315,7 @@ public class AntTypeDefinition {
noArg = false;
}
//now we instantiate
T o = ctor.newInstance(
((noArg) ? new Object[0] : new Object[] {project}));
T o = ctor.newInstance(noArg ? new Object[0] : new Object[] {project});

//set up project references.
project.setProjectReference(o);
@@ -331,12 +330,12 @@ public class AntTypeDefinition {
* @return true if the definitions are the same.
*/
public boolean sameDefinition(AntTypeDefinition other, Project project) {
return (other != null && other.getClass() == getClass()
return other != null && other.getClass() == getClass()
&& other.getTypeClass(project).equals(getTypeClass(project))
&& other.getExposedClass(project).equals(getExposedClass(project))
&& other.restrict == restrict
&& other.adapterClass == adapterClass
&& other.adaptToClass == adaptToClass);
&& other.adaptToClass == adaptToClass;
}

/**


+ 3
- 3
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -710,9 +710,9 @@ public class ComponentHelper {
}
Class<?> oldClass = old.getExposedClass(project);
boolean isTask = oldClass != null && Task.class.isAssignableFrom(oldClass);
project.log("Trying to override old definition of "
+ (isTask ? "task " : "datatype ") + name, (def.similarDefinition(old,
project)) ? Project.MSG_VERBOSE : Project.MSG_WARN);
project.log(String.format("Trying to override old definition of %s %s",
isTask ? "task" : "datatype", name), def.similarDefinition(old,
project) ? Project.MSG_VERBOSE : Project.MSG_WARN);
}
project.log(" +Datatype " + name + " " + def.getClassName(), Project.MSG_DEBUG);
antTypeTable.put(name, def);


+ 5
- 5
src/main/org/apache/tools/ant/Project.java View File

@@ -268,7 +268,7 @@ public class Project implements ResourceFactory {
public Project createSubProject() {
Project subProject = null;
try {
subProject = (getClass().newInstance());
subProject = getClass().newInstance();
} catch (final Exception e) {
subProject = new Project();
}
@@ -927,7 +927,7 @@ public class Project implements ResourceFactory {
throw new BuildException("Ant cannot work on Java prior to 1.8");
}
log("Detected Java version: " + javaVersion + " in: "
+ System.getProperty("java.home"), MSG_VERBOSE);
+ JavaEnvUtils.getJavaHome(), MSG_VERBOSE);

log("Detected OS: " + System.getProperty("os.name"), MSG_VERBOSE);
}
@@ -1716,9 +1716,9 @@ public class Project implements ResourceFactory {
* <code>false</code> otherwise.
*/
public static boolean toBoolean(final String s) {
return ("on".equalsIgnoreCase(s)
return "on".equalsIgnoreCase(s)
|| "true".equalsIgnoreCase(s)
|| "yes".equalsIgnoreCase(s));
|| "yes".equalsIgnoreCase(s);
}

/**
@@ -1828,7 +1828,7 @@ public class Project implements ResourceFactory {
.collect(Collectors.joining(","))
+ " is " + ret, MSG_VERBOSE);

final Vector<Target> complete = (returnAll) ? ret : new Vector<>(ret);
final Vector<Target> complete = returnAll ? ret : new Vector<>(ret);
for (final String curTarget : targetTable.keySet()) {
final String st = state.get(curTarget);
if (st == null) {


+ 1
- 1
src/main/org/apache/tools/ant/dispatch/DispatchUtils.java View File

@@ -104,7 +104,7 @@ public class DispatchUtils {
} catch (InvocationTargetException ie) {
Throwable t = ie.getTargetException();
if (t instanceof BuildException) {
throw ((BuildException) t);
throw (BuildException) t;
} else {
throw new BuildException(t);
}


+ 6
- 10
src/main/org/apache/tools/ant/listener/MailLogger.java View File

@@ -143,16 +143,13 @@ public class MailLogger extends DefaultLogger {
}
Values values = new Values()
.mailhost(getValue(properties, "mailhost", "localhost"))
.port(Integer.parseInt(
getValue(
properties, "port",
String.valueOf(MailMessage.DEFAULT_PORT))))
.port(Integer.parseInt(getValue(properties, "port",
String.valueOf(MailMessage.DEFAULT_PORT))))
.user(getValue(properties, "user", ""))
.password(getValue(properties, "password", ""))
.ssl(Project.toBoolean(getValue(properties,
"ssl", "off")))
.ssl(Project.toBoolean(getValue(properties, "ssl", "off")))
.starttls(Project.toBoolean(getValue(properties,
"starttls.enable", "off")))
"starttls.enable", "off")))
.from(getValue(properties, "from", null))
.replytoList(getValue(properties, "replyto", ""))
.toList(getValue(properties, prefix + ".to", null))
@@ -161,9 +158,8 @@ public class MailLogger extends DefaultLogger {
.mimeType(getValue(properties, "mimeType", DEFAULT_MIME_TYPE))
.charset(getValue(properties, "charset", ""))
.body(getValue(properties, prefix + ".body", ""))
.subject(getValue(
properties, prefix + ".subject",
(success) ? "Build Success" : "Build Failure"));
.subject(getValue(properties, prefix + ".subject",
success ? "Build Success" : "Build Failure"));
if (values.user().isEmpty()
&& values.password().isEmpty()
&& !values.ssl() && !values.starttls()) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java View File

@@ -364,7 +364,7 @@ public abstract class AbstractCvsTask extends Task {
log("Caught exception: " + e.getMessage(), Project.MSG_WARN);
} catch (BuildException e) {
if (failOnError) {
throw(e);
throw e;
}
Throwable t = e.getCause();
if (t == null) {


+ 3
- 3
src/main/org/apache/tools/ant/taskdefs/Exit.java View File

@@ -134,8 +134,8 @@ public class Exit extends Task {
*/
@Override
public void execute() throws BuildException {
boolean fail = (nestedConditionPresent()) ? testNestedCondition()
: (testIfCondition() && testUnlessCondition());
boolean fail = nestedConditionPresent() ? testNestedCondition()
: testIfCondition() && testUnlessCondition();
if (fail) {
String text = null;
if (message != null && !message.trim().isEmpty()) {
@@ -231,7 +231,7 @@ public class Exit extends Task {
* @return <code>boolean</code>.
*/
private boolean nestedConditionPresent() {
return (nestedCondition != null);
return nestedCondition != null;
}

}

+ 3
- 4
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -420,10 +420,9 @@ public class FixCRLF extends MatchingTask implements ChainableReader {
throws BuildException {
this.srcFile = srcFile;
try {
reader = new BufferedReader(
((encoding == null) ? new FileReader(srcFile)
: new InputStreamReader(
Files.newInputStream(srcFile.toPath()), encoding)), INBUFLEN);
reader = new BufferedReader(encoding == null ? new FileReader(srcFile)
: new InputStreamReader(Files.newInputStream(srcFile.toPath()),
encoding), INBUFLEN);

nextLine();
} catch (IOException e) {


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/JikesOutputParser.java View File

@@ -169,9 +169,9 @@ public class JikesOutputParser implements ExecuteStreamHandler {

private void log(String line) {
if (!emacsMode) {
task.log("", (error ? Project.MSG_ERR : Project.MSG_WARN));
task.log("", error ? Project.MSG_ERR : Project.MSG_WARN);
}
task.log(line, (error ? Project.MSG_ERR : Project.MSG_WARN));
task.log(line, error ? Project.MSG_ERR : Project.MSG_WARN);
}

/**


+ 8
- 9
src/main/org/apache/tools/ant/taskdefs/PreSetDef.java View File

@@ -266,9 +266,9 @@ public class PreSetDef extends AntlibDefinition implements TaskContainer {
*/
@Override
public boolean sameDefinition(AntTypeDefinition other, Project project) {
return (other != null && other.getClass() == getClass() && parent != null
&& parent.sameDefinition(((PreSetDefinition) other).parent, project)
&& element.similar(((PreSetDefinition) other).element));
return other != null && other.getClass() == getClass() && parent != null
&& parent.sameDefinition(((PreSetDefinition) other).parent, project)
&& element.similar(((PreSetDefinition) other).element);
}

/**
@@ -279,12 +279,11 @@ public class PreSetDef extends AntlibDefinition implements TaskContainer {
* @return true if the definitions are similar.
*/
@Override
public boolean similarDefinition(
AntTypeDefinition other, Project project) {
return (other != null && other.getClass().getName().equals(
getClass().getName()) && parent != null
&& parent.similarDefinition(((PreSetDefinition) other).parent, project)
&& element.similar(((PreSetDefinition) other).element));
public boolean similarDefinition(AntTypeDefinition other, Project project) {
return other != null && other.getClass().getName().equals(getClass().getName())
&& parent != null
&& parent.similarDefinition(((PreSetDefinition) other).parent, project)
&& element.similar(((PreSetDefinition) other).element);
}
}
}

+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Recorder.java View File

@@ -114,7 +114,7 @@ public class Recorder extends Task implements SubBuildListener {
* @param append if true, append to a previous file.
*/
public void setAppend(boolean append) {
this.append = (append ? Boolean.TRUE : Boolean.FALSE);
this.append = append ? Boolean.TRUE : Boolean.FALSE;
}




+ 2
- 4
src/main/org/apache/tools/ant/taskdefs/Redirector.java View File

@@ -695,8 +695,7 @@ public class Redirector {
/** outStreams */
private void outStreams() {
if (out != null && out.length > 0) {
final String logHead = "Output "
+ ((appendOut) ? "appended" : "redirected") + " to ";
final String logHead = "Output " + (appendOut ? "appended" : "redirected") + " to ";
outputStream = foldFiles(out, logHead, Project.MSG_VERBOSE,
appendOut, createEmptyFilesOut);
}
@@ -717,8 +716,7 @@ public class Redirector {

private void errorStreams() {
if (error != null && error.length > 0) {
final String logHead = "Error "
+ ((appendErr) ? "appended" : "redirected") + " to ";
final String logHead = "Error " + (appendErr ? "appended" : "redirected") + " to ";
errorStream = foldFiles(error, logHead, Project.MSG_VERBOSE,
appendErr, createEmptyFilesErr);
} else if (!(logError || outputStream == null) && errorProperty == null) {


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/Touch.java View File

@@ -254,7 +254,7 @@ public class Touch extends Task {
}
}
log("Setting millis to " + workmillis + " from datetime attribute",
((millis < 0) ? Project.MSG_DEBUG : Project.MSG_VERBOSE));
millis < 0 ? Project.MSG_DEBUG : Project.MSG_VERBOSE);
setMillis(workmillis);
// only set if successful to this point:
dateTimeConfigured = true;
@@ -352,7 +352,7 @@ public class Touch extends Task {
private void touch(File file, long modTime) {
if (!file.exists()) {
log("Creating " + file,
((verbose) ? Project.MSG_INFO : Project.MSG_VERBOSE));
verbose ? Project.MSG_INFO : Project.MSG_VERBOSE);
try {
FILE_UTILS.createNewFile(file, mkdirs);
} catch (IOException ioe) {


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/condition/Os.java View File

@@ -264,12 +264,12 @@ public class Os implements Condition {
boolean isNT = false;
if (isWindows) {
//there are only four 9x platforms that we look for
is9x = (OS_NAME.contains("95")
//wince isn't really 9x, but crippled enough to
//be a muchness. Ant doesn't run on CE, anyway.
is9x = OS_NAME.contains("95")
|| OS_NAME.contains("98")
|| OS_NAME.contains("me")
//wince isn't really 9x, but crippled enough to
//be a muchness. Ant doesn't run on CE, anyway.
|| OS_NAME.contains("ce"));
|| OS_NAME.contains("ce");
isNT = !is9x;
}
switch (family) {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/SchemaValidate.java View File

@@ -479,7 +479,7 @@ public class SchemaValidate extends XMLValidateTask {
public int hashCode() {
int result;
// CheckStyle:MagicNumber OFF
result = (namespace == null ? 0 : namespace.hashCode());
result = namespace == null ? 0 : namespace.hashCode();
result = 29 * result + (file == null ? 0 : file.hashCode());
result = 29 * result + (url == null ? 0 : url.hashCode());
// CheckStyle:MagicNumber OFF


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java View File

@@ -364,7 +364,7 @@ public class XMLValidateTask extends Task {
* @return true when a SAX1 parser is in use
*/
protected boolean isSax1Parser() {
return (xmlReader instanceof ParserAdapter);
return xmlReader instanceof ParserAdapter;
}

/**


+ 2
- 8
src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java View File

@@ -1081,12 +1081,7 @@ public class IPlanetEjbc {
* be run to bring the stubs and skeletons up to date.
*/
public boolean mustBeRecompiled(File destDir) {

long sourceModified = sourceClassesModified(destDir);

long destModified = destClassesModified(destDir);

return (destModified < sourceModified);
return destClassesModified(destDir) < sourceClassesModified(destDir);
}

/**
@@ -1236,8 +1231,7 @@ public class IPlanetEjbc {
* names for the stubs and skeletons to be generated.
*/
private String[] classesToGenerate() {
String[] classnames = (iiop)
? new String[NUM_CLASSES_WITH_IIOP]
String[] classnames = iiop ? new String[NUM_CLASSES_WITH_IIOP]
: new String[NUM_CLASSES_WITHOUT_IIOP];

final String remotePkg = remote.getPackageName() + ".";


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java View File

@@ -467,7 +467,7 @@ public final class Extension {
* @return true if the specified extension is compatible with this extension
*/
public boolean isCompatibleWith(final Extension required) {
return (COMPATIBLE == getCompatibilityWith(required));
return COMPATIBLE == getCompatibilityWith(required);
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -876,7 +876,7 @@ public class FTP extends Task implements FTPTaskConfig {
* @return true if the file exists
*/
public boolean exists() {
return (ftpFile != null);
return ftpFile != null;
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/types/EnumeratedAttribute.java View File

@@ -103,7 +103,7 @@ public abstract class EnumeratedAttribute {
* @return true if the value is valid
*/
public final boolean containsValue(String value) {
return (indexOfValue(value) != -1);
return indexOfValue(value) != -1;
}

/**


+ 1
- 2
src/main/org/apache/tools/ant/types/Path.java View File

@@ -331,8 +331,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
* @param tryUserDir if true try the user directory if the file is not present
*/
public void addExisting(Path source, boolean tryUserDir) {
File userDir = (tryUserDir) ? new File(System.getProperty("user.dir"))
: null;
File userDir = tryUserDir ? new File(System.getProperty("user.dir")) : null;

for (String name : source.list()) {
File f = resolveFile(getProject(), name);


+ 1
- 1
src/main/org/apache/tools/ant/types/Permissions.java View File

@@ -348,7 +348,7 @@ public class Permissions {
*/
@Override
public String toString() {
return ("Permission: " + className + " (\"" + name + "\", \"" + actions + "\")");
return String.format("Permission: %s (\"%s\", \"%s\")", className, name, actions);
}
}
}

+ 3
- 4
src/main/org/apache/tools/ant/types/RedirectorElement.java View File

@@ -342,7 +342,7 @@ public class RedirectorElement extends DataType {
if (isReference()) {
throw tooManyAttributes();
}
this.append = ((append) ? Boolean.TRUE : Boolean.FALSE);
this.append = append ? Boolean.TRUE : Boolean.FALSE;
}

/**
@@ -356,7 +356,7 @@ public class RedirectorElement extends DataType {
if (isReference()) {
throw tooManyAttributes();
}
this.alwaysLog = ((alwaysLog) ? Boolean.TRUE : Boolean.FALSE);
this.alwaysLog = alwaysLog ? Boolean.TRUE : Boolean.FALSE;
}

/**
@@ -368,8 +368,7 @@ public class RedirectorElement extends DataType {
if (isReference()) {
throw tooManyAttributes();
}
this.createEmptyFiles = ((createEmptyFiles)
? Boolean.TRUE : Boolean.FALSE);
this.createEmptyFiles = createEmptyFiles ? Boolean.TRUE : Boolean.FALSE;
}

/**


+ 4
- 4
src/main/org/apache/tools/ant/types/selectors/SelectorUtils.java View File

@@ -278,8 +278,8 @@ public final class SelectorUtils {
}
// Find the pattern between padIdxStart & padIdxTmp in str between
// strIdxStart & strIdxEnd
int patLength = (patIdxTmp - patIdxStart - 1);
int strLength = (strIdxEnd - strIdxStart + 1);
int patLength = patIdxTmp - patIdxStart - 1;
int strLength = strIdxEnd - strIdxStart + 1;
int foundIdx = -1;
strLoop:
for (int i = 0; i <= strLength - patLength; i++) {
@@ -433,8 +433,8 @@ public final class SelectorUtils {
}
// Find the pattern between padIdxStart & padIdxTmp in str between
// strIdxStart & strIdxEnd
int patLength = (patIdxTmp - patIdxStart - 1);
int strLength = (strIdxEnd - strIdxStart + 1);
int patLength = patIdxTmp - patIdxStart - 1;
int strLength = strIdxEnd - strIdxStart + 1;
int foundIdx = -1;
strLoop:
for (int i = 0; i <= strLength - patLength; i++) {


+ 1
- 1
src/main/org/apache/tools/ant/types/selectors/modifiedselector/EqualComparator.java View File

@@ -45,7 +45,7 @@ public class EqualComparator implements Comparator<Object> {
}
return 0;
}
return (o1.equals(o2)) ? 0 : 1;
return o1.equals(o2) ? 0 : 1;
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/types/selectors/modifiedselector/ModifiedSelector.java View File

@@ -459,7 +459,7 @@ public class ModifiedSelector extends BaseExtendSelector
+ resource.getName()
+ "' does not provide an InputStream, so it is not checked. "
+ "According to 'selres' attribute value it is "
+ ((selectResourcesWithoutInputStream) ? "" : " not")
+ (selectResourcesWithoutInputStream ? "" : " not")
+ "selected.", Project.MSG_INFO);
return selectResourcesWithoutInputStream;
} catch (Exception e) {


+ 1
- 1
src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java View File

@@ -118,7 +118,7 @@ public class PropertiesfileCache implements Cache {
*/
@Override
public boolean isValid() {
return (cachefile != null);
return cachefile != null;
}




+ 1
- 1
src/main/org/apache/tools/ant/util/Base64Converter.java View File

@@ -91,7 +91,7 @@ public class Base64Converter {
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & POS_1_MASK) >> POS_1_SHIFT;
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & POS_0_MASK);
bits6 = bits24 & POS_0_MASK;
out[outIndex++] = ALPHABET[bits6];
}
if (octetString.length - i == 2) {


+ 1
- 1
src/main/org/apache/tools/ant/util/DOMElementWriter.java View File

@@ -515,7 +515,7 @@ public class DOMElementWriter {
int prevEnd = 0;
int cdataEndPos = value.indexOf("]]>");
while (prevEnd < len) {
final int end = (cdataEndPos < 0 ? len : cdataEndPos);
final int end = cdataEndPos < 0 ? len : cdataEndPos;
// Write out stretches of legal characters in the range [prevEnd, end).
int prevLegalCharPos = prevEnd;
while (prevLegalCharPos < end) {


+ 1
- 1
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -1181,7 +1181,7 @@ public class FileUtils {
if (!l.endsWith(File.separator)) {
l += File.separator;
}
return (p.startsWith(l)) ? p.substring(l.length()) : p;
return p.startsWith(l) ? p.substring(l.length()) : p;
}

/**


+ 1
- 1
src/main/org/apache/tools/bzip2/BZip2Constants.java View File

@@ -42,7 +42,7 @@ public interface BZip2Constants {
int N_GROUPS = 6;
int G_SIZE = 50;
int N_ITERS = 4;
int MAX_SELECTORS = (2 + (900000 / G_SIZE));
int MAX_SELECTORS = 2 + 900000 / G_SIZE;
int NUM_OVERSHOOT_BYTES = 20;

/**


+ 8
- 8
src/main/org/apache/tools/bzip2/BlockSort.java View File

@@ -686,17 +686,17 @@ class BlockSort {
i2 -= lastPlus1;
}
workDoneShadow++;
} else if ((quadrant[i1 + 3] > quadrant[i2 + 3])) {
} else if (quadrant[i1 + 3] > quadrant[i2 + 3]) {
continue HAMMER;
} else {
break HAMMER;
}
} else if ((block[i1 + 4] & 0xff) > (block[i2 + 4] & 0xff)) {
} else if ((block[i2 + 4] & 0xff) < (block[i1 + 4] & 0xff)) {
continue HAMMER;
} else {
break HAMMER;
}
} else if ((quadrant[i1 + 2] > quadrant[i2 + 2])) {
} else if (quadrant[i1 + 2] > quadrant[i2 + 2]) {
continue HAMMER;
} else {
break HAMMER;
@@ -706,7 +706,7 @@ class BlockSort {
} else {
break HAMMER;
}
} else if ((quadrant[i1 + 1] > quadrant[i2 + 1])) {
} else if (quadrant[i1 + 1] > quadrant[i2 + 1]) {
continue HAMMER;
} else {
break HAMMER;
@@ -716,7 +716,7 @@ class BlockSort {
} else {
break HAMMER;
}
} else if ((quadrant[i1] > quadrant[i2])) {
} else if (quadrant[i1] > quadrant[i2]) {
continue HAMMER;
} else {
break HAMMER;
@@ -900,8 +900,8 @@ class BlockSort {
}
}

private static final int SETMASK = (1 << 21);
private static final int CLEARMASK = (~SETMASK);
private static final int SETMASK = 1 << 21;
private static final int CLEARMASK = ~SETMASK;

final void mainSort(final CBZip2OutputStream.Data dataShadow,
final int lastShadow) {
@@ -1024,7 +1024,7 @@ class BlockSort {
copy[j] = ftab[(j << 8) + ss] & CLEARMASK;
}

for (int j = ftab[ss << 8] & CLEARMASK, hj = (ftab[(ss + 1) << 8] & CLEARMASK); j < hj; j++) {
for (int j = ftab[ss << 8] & CLEARMASK, hj = ftab[ss + 1 << 8] & CLEARMASK; j < hj; j++) {
final int fmap_j = fmap[j];
c1 = block[fmap_j] & 0xff;
if (!bigDone[c1]) {


+ 6
- 11
src/main/org/apache/tools/bzip2/CBZip2OutputStream.java View File

@@ -143,14 +143,14 @@ public class CBZip2OutputStream extends OutputStream
* purposes. If you don't know what it means then you don't need
* it.
*/
protected static final int SETMASK = (1 << 21);
protected static final int SETMASK = 1 << 21;

/**
* This constant is accessible by subclasses for historical
* purposes. If you don't know what it means then you don't need
* it.
*/
protected static final int CLEARMASK = (~SETMASK);
protected static final int CLEARMASK = ~SETMASK;

/**
* This constant is accessible by subclasses for historical
@@ -322,14 +322,9 @@ public class CBZip2OutputStream extends OutputStream

final int weight_n1 = weight[n1];
final int weight_n2 = weight[n2];
weight[nNodes] = (((weight_n1 & 0xffffff00)
+ (weight_n2 & 0xffffff00))
|
(1 + (((weight_n1 & 0x000000ff)
> (weight_n2 & 0x000000ff))
? (weight_n1 & 0x000000ff)
: (weight_n2 & 0x000000ff))
));
weight[nNodes] = (weight_n1 & 0xffffff00) + (weight_n2 & 0xffffff00)
| 1 + ((weight_n1 & 0x000000ff) > (weight_n2 & 0x000000ff)
? weight_n1 & 0x000000ff : weight_n2 & 0x000000ff);

parent[nNodes] = -1;
nHeap++;
@@ -1565,7 +1560,7 @@ public class CBZip2OutputStream extends OutputStream
super();

final int n = blockSize100k * BZip2Constants.baseBlockSize;
this.block = new byte[(n + 1 + NUM_OVERSHOOT_BYTES)];
this.block = new byte[n + 1 + NUM_OVERSHOOT_BYTES];
this.fmap = new int[n];
this.sfmap = new char[2 * n];
}


+ 15
- 27
src/main/org/apache/tools/tar/TarBuffer.java View File

@@ -44,10 +44,10 @@ import java.util.Arrays;
public class TarBuffer {

/** Default record size */
public static final int DEFAULT_RCDSIZE = (512);
public static final int DEFAULT_RCDSIZE = 512;

/** Default block size */
public static final int DEFAULT_BLKSIZE = (DEFAULT_RCDSIZE * 20);
public static final int DEFAULT_BLKSIZE = DEFAULT_RCDSIZE * 20;

private InputStream inStream;
private OutputStream outStream;
@@ -123,7 +123,7 @@ public class TarBuffer {
this.debug = false;
this.blockSize = blockSize;
this.recordSize = recordSize;
this.recsPerBlock = (this.blockSize / this.recordSize);
this.recsPerBlock = this.blockSize / this.recordSize;
this.blockBuffer = new byte[this.blockSize];

if (this.inStream != null) {
@@ -183,8 +183,7 @@ public class TarBuffer {
*/
public void skipRecord() throws IOException {
if (debug) {
System.err.println("SkipRecord: recIdx = " + currRecIdx
+ " blkIdx = " + currBlkIdx);
System.err.printf("SkipRecord: recIdx = %d blkIdx = %d%n", currRecIdx, currBlkIdx);
}

if (inStream == null) {
@@ -206,8 +205,7 @@ public class TarBuffer {
*/
public byte[] readRecord() throws IOException {
if (debug) {
System.err.println("ReadRecord: recIdx = " + currRecIdx
+ " blkIdx = " + currBlkIdx);
System.err.printf("ReadRecord: recIdx = %d blkIdx = %d%n", currRecIdx, currBlkIdx);
}

if (inStream == null) {
@@ -223,9 +221,7 @@ public class TarBuffer {

byte[] result = new byte[recordSize];

System.arraycopy(blockBuffer,
(currRecIdx * recordSize), result, 0,
recordSize);
System.arraycopy(blockBuffer, currRecIdx * recordSize, result, 0, recordSize);

currRecIdx++;

@@ -250,8 +246,7 @@ public class TarBuffer {
int bytesNeeded = blockSize;

while (bytesNeeded > 0) {
long numBytes = inStream.read(blockBuffer, offset,
bytesNeeded);
long numBytes = inStream.read(blockBuffer, offset, bytesNeeded);

//
// NOTE
@@ -289,9 +284,8 @@ public class TarBuffer {

if (numBytes != blockSize) {
if (debug) {
System.err.println("ReadBlock: INCOMPLETE READ "
+ numBytes + " of " + blockSize
+ " bytes read.");
System.err.printf("ReadBlock: INCOMPLETE READ %d of %d bytes read.%n",
numBytes, blockSize);
}
}
}
@@ -328,8 +322,8 @@ public class TarBuffer {
*/
public void writeRecord(byte[] record) throws IOException {
if (debug) {
System.err.println("WriteRecord: recIdx = " + currRecIdx
+ " blkIdx = " + currBlkIdx);
System.err.printf("WriteRecord: recIdx = %d blkIdx = %d%n",
currRecIdx, currBlkIdx);
}

if (outStream == null) {
@@ -350,9 +344,7 @@ public class TarBuffer {
writeBlock();
}

System.arraycopy(record, 0, blockBuffer,
(currRecIdx * recordSize),
recordSize);
System.arraycopy(record, 0, blockBuffer, currRecIdx * recordSize, recordSize);

currRecIdx++;
}
@@ -368,8 +360,7 @@ public class TarBuffer {
*/
public void writeRecord(byte[] buf, int offset) throws IOException {
if (debug) {
System.err.println("WriteRecord: recIdx = " + currRecIdx
+ " blkIdx = " + currBlkIdx);
System.err.printf("WriteRecord: recIdx = %d blkIdx = %d%n", currRecIdx, currBlkIdx);
}

if (outStream == null) {
@@ -390,9 +381,7 @@ public class TarBuffer {
writeBlock();
}

System.arraycopy(buf, offset, blockBuffer,
(currRecIdx * recordSize),
recordSize);
System.arraycopy(buf, offset, blockBuffer, currRecIdx * recordSize, recordSize);

currRecIdx++;
}
@@ -447,8 +436,7 @@ public class TarBuffer {
if (outStream != null) {
flushBlock();

if (outStream != System.out
&& outStream != System.err) {
if (outStream != System.out && outStream != System.err) {
outStream.close();

outStream = null;


+ 1
- 1
src/main/org/apache/tools/tar/TarInputStream.java View File

@@ -215,7 +215,7 @@ public class TarInputStream extends FilterInputStream {
}
skip -= numRead;
}
return (numToSkip - skip);
return numToSkip - skip;
}

/**


+ 1
- 1
src/main/org/apache/tools/zip/ZipEightByteInteger.java View File

@@ -136,7 +136,7 @@ public final class ZipEightByteInteger {
public static byte[] getBytes(BigInteger value) {
byte[] result = new byte[8];
long val = value.longValue();
result[0] = (byte) ((val & BYTE_MASK));
result[0] = (byte) (val & BYTE_MASK);
result[BYTE_1] = (byte) ((val & BYTE_1_MASK) >> BYTE_1_SHIFT);
result[BYTE_2] = (byte) ((val & BYTE_2_MASK) >> BYTE_2_SHIFT);
result[BYTE_3] = (byte) ((val & BYTE_3_MASK) >> BYTE_3_SHIFT);


+ 1
- 2
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -1003,8 +1003,7 @@ public class ZipFile implements Closeable {
if (ent2 == null) {
return -1;
}
final long val = (ent1.getOffsetEntry().headerOffset
- ent2.getOffsetEntry().headerOffset);
final long val = ent1.getOffsetEntry().headerOffset - ent2.getOffsetEntry().headerOffset;
return val == 0 ? 0 : val < 0 ? -1 : +1;
};



+ 1
- 1
src/main/org/apache/tools/zip/ZipLong.java View File

@@ -127,7 +127,7 @@ public final class ZipLong implements Cloneable {
* must be non-negative and no larger than <tt>buf.length-4</tt>
*/
public static void putLong(long value, byte[] buf, int offset) {
buf[offset++] = (byte) ((value & BYTE_MASK));
buf[offset++] = (byte) (value & BYTE_MASK);
buf[offset++] = (byte) ((value & BYTE_1_MASK) >> BYTE_1_SHIFT);
buf[offset++] = (byte) ((value & BYTE_2_MASK) >> BYTE_2_SHIFT);
buf[offset] = (byte) ((value & BYTE_3_MASK) >> BYTE_3_SHIFT);


+ 3
- 5
src/main/org/apache/tools/zip/ZipOutputStream.java View File

@@ -1565,8 +1565,8 @@ public class ZipOutputStream extends FilterOutputStream {
}
// requires version 2 as we are going to store length info
// in the data descriptor
return (isDeflatedToOutputStream(zipMethod))
? DATA_DESCRIPTOR_MIN_VERSION : INITIAL_VERSION;
return isDeflatedToOutputStream(zipMethod)
? DATA_DESCRIPTOR_MIN_VERSION : INITIAL_VERSION;
}

private boolean isDeflatedToOutputStream(int zipMethod) {
@@ -1613,9 +1613,7 @@ public class ZipOutputStream extends FilterOutputStream {
* @return boolean
*/
private boolean hasZip64Extra(ZipEntry ze) {
return ze.getExtraField(Zip64ExtendedInformationExtraField
.HEADER_ID)
!= null;
return ze.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID) != null;
}

/**


+ 1
- 1
src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java View File

@@ -770,7 +770,7 @@ public class ModifiedSelectorTest {
results); // result
} finally {
// cleanup the environment
(new File(cachefile)).delete();
new File(cachefile).delete();
bft.deletePropertiesfile();
}
}


Loading…
Cancel
Save