File TarArchiveInputStream.java
has 415 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You 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
Method parsePaxHeaders
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
Map<String, String> parsePaxHeaders(final InputStream i) {
if (i == null) {
return null;
}
final Map<String, String> headers = new HashMap<String, String>(globalPaxHeaders);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
TarArchiveInputStream
has 34 methods (exceeds 20 allowed). Consider refactoring. Open
public class TarArchiveInputStream extends InputStream {
private final byte[] single = new byte[1];
private static final int BYTE_MASK = 0xFF;
/** holds the number of bytes read in this stream */
Method getNextTarEntry
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
public TarArchiveEntry getNextTarEntry() {
if (isAtEOF()) {
return null;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getNextTarEntry
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
public TarArchiveEntry getNextTarEntry() {
if (isAtEOF()) {
return null;
}
Method parsePaxHeaders
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
Map<String, String> parsePaxHeaders(final InputStream i) {
if (i == null) {
return null;
}
final Map<String, String> headers = new HashMap<String, String>(globalPaxHeaders);
Method create
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static TarArchiveInputStream create(String gZippedFile) {
if (gZippedFile == null) {
return null;
}
File file = new File(gZippedFile);
Method create
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public static TarArchiveInputStream create(String gZippedFile) {
if (gZippedFile == null) {
return null;
}
File file = new File(gZippedFile);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method read
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
@Override
public int read(byte[] buf, final int offset, int numToRead) {
int totalRead = 0;
if (isAtEOF() || isDirectory() || entryOffset >= entrySize) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method matches
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static boolean matches(byte[] signature, int length) {
if (length < TarUtils.VERSION_OFFSET + TarUtils.VERSIONLEN) {
return false;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return currEntry;
Avoid too many return
statements within this method. Open
return null;
Avoid too many return
statements within this method. Open
return totalRead;
Method getLongNameData
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected byte[] getLongNameData() {
/* read in the name */
final ByteArrayOutputStream longName = new ByteArrayOutputStream();
int length = 0;
try {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method tryToConsumeSecondEOFRecord
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private boolean tryToConsumeSecondEOFRecord() {
if (is == null) {
return false;
}
boolean shouldReset = true;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
These nested if statements could be combined Open
if (logger != null) {
logger.error(this, "getNextTarEntry", "ERROR readOldGNUSparse");
}
- Read upRead up
- Exclude checks
CollapsibleIfStatements
Since: PMD 3.1
Priority: Medium
Categories: Style
Remediation Points: 50000
Sometimes two consecutive 'if' statements can be consolidated by separating their conditions with a boolean short-circuit operator.
Example:
void bar() {
if (x) { // original implementation
if (y) {
// do stuff
}
}
}
void bar() {
if (x && y) { // optimized implementation
// do stuff
}
}
Avoid returning from a finally block Open
return false;
- Read upRead up
- Exclude checks
ReturnFromFinallyBlock
Since: PMD 1.05
Priority: Medium
Categories: Style
Remediation Points: 50000
Avoid returning from a finally block, this can discard exceptions.
Example:
public class Bar {
public String foo() {
try {
throw new Exception( 'My Exception' );
} catch (Exception e) {
throw e;
} finally {
return 'A. O. K.'; // return not recommended here
}
}
}