Clean up redundant code constructs
Results of the following IntelliJ inspections: * Redundant 'isInstance' or 'cast' call * Redundant array creation * Redundant Collection operation * Redundant String operation * Redundant type cast The only manual change was to remove a suppression and comment about a redundant cast which doesn't appear to be an issue in the current version of JDK 8 Change-Id: I34a70d436512cc4efe9dafb0917be3dfce4ba06b
This commit is contained in:
parent
4e22200be9
commit
737b035223
@ -725,7 +725,7 @@ public abstract class AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final List<Character> RANDOM =
|
private static final List<Character> RANDOM =
|
||||||
Chars.asList(new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'});
|
Chars.asList('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h');
|
||||||
|
|
||||||
protected PushOneCommit.Result amendChange(String changeId) throws Exception {
|
protected PushOneCommit.Result amendChange(String changeId) throws Exception {
|
||||||
return amendChange(changeId, "refs/for/master", admin, testRepo);
|
return amendChange(changeId, "refs/for/master", admin, testRepo);
|
||||||
|
@ -127,7 +127,7 @@ public class AsciiDoctor {
|
|||||||
int equalsIndex = attribute.indexOf('=');
|
int equalsIndex = attribute.indexOf('=');
|
||||||
if (equalsIndex > -1) {
|
if (equalsIndex > -1) {
|
||||||
String name = attribute.substring(0, equalsIndex);
|
String name = attribute.substring(0, equalsIndex);
|
||||||
String value = attribute.substring(equalsIndex + 1, attribute.length());
|
String value = attribute.substring(equalsIndex + 1);
|
||||||
|
|
||||||
attributeValues.put(name, value);
|
attributeValues.put(name, value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -60,7 +60,7 @@ public class ParameterizedString {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
raw.append(pattern.substring(i, b));
|
raw.append(pattern, i, b);
|
||||||
ops.add(new Constant(pattern.substring(i, b)));
|
ops.add(new Constant(pattern.substring(i, b)));
|
||||||
|
|
||||||
// "${parameter[.functions...]}" -> "parameter[.functions...]"
|
// "${parameter[.functions...]}" -> "parameter[.functions...]"
|
||||||
|
@ -212,7 +212,7 @@ public class GitOverHttpServlet extends GitServlet {
|
|||||||
}
|
}
|
||||||
// Explicit cast is required to compile under Servlet API 2.5, where the return type is raw Map.
|
// Explicit cast is required to compile under Servlet API 2.5, where the return type is raw Map.
|
||||||
@SuppressWarnings("cast")
|
@SuppressWarnings("cast")
|
||||||
Map<String, String[]> parameterMap = (Map<String, String[]>) request.getParameterMap();
|
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||||
ImmutableListMultimap.Builder<String, String> b = ImmutableListMultimap.builder();
|
ImmutableListMultimap.Builder<String, String> b = ImmutableListMultimap.builder();
|
||||||
parameterMap.forEach(b::putAll);
|
parameterMap.forEach(b::putAll);
|
||||||
return b.build();
|
return b.build();
|
||||||
|
@ -1361,9 +1361,7 @@ public class RestApiServlet extends HttpServlet {
|
|||||||
// generated.
|
// generated.
|
||||||
TraceContext traceContext =
|
TraceContext traceContext =
|
||||||
TraceContext.newTrace(
|
TraceContext.newTrace(
|
||||||
doTrace,
|
doTrace, traceId1, (tagName, traceId) -> res.setHeader(X_GERRIT_TRACE, traceId));
|
||||||
traceId1,
|
|
||||||
(tagName, traceId) -> res.setHeader(X_GERRIT_TRACE, traceId.toString()));
|
|
||||||
// If a second trace ID was specified, add a tag for it as well.
|
// If a second trace ID was specified, add a tag for it as well.
|
||||||
if (traceId2 != null) {
|
if (traceId2 != null) {
|
||||||
traceContext.addTag(RequestId.Type.TRACE_ID, traceId2);
|
traceContext.addTag(RequestId.Type.TRACE_ID, traceId2);
|
||||||
|
@ -324,7 +324,7 @@ public final class GerritLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String name = ze.getName();
|
String name = ze.getName();
|
||||||
jars.put(name.substring(name.lastIndexOf('/'), name.length()), tmp.toURI().toURL());
|
jars.put(name.substring(name.lastIndexOf('/')), tmp.toURI().toURL());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void move(SortedMap<String, URL> jars, String prefix, List<URL> extapi) {
|
private static void move(SortedMap<String, URL> jars, String prefix, List<URL> extapi) {
|
||||||
|
@ -103,6 +103,6 @@ public class MailHeaderParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String extractFooter(String key, String line) {
|
private static String extractFooter(String key, String line) {
|
||||||
return line.substring(line.indexOf(key) + key.length(), line.length()).trim();
|
return line.substring(line.indexOf(key) + key.length()).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ abstract class BucketedCallback<V> implements BucketedMetric {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<Object, Metric> getCells() {
|
public Map<Object, Metric> getCells() {
|
||||||
return Maps.transformValues(cells, in -> (Metric) in);
|
return Maps.transformValues(cells, in -> in);
|
||||||
}
|
}
|
||||||
|
|
||||||
final class ValueGauge implements Gauge<V> {
|
final class ValueGauge implements Gauge<V> {
|
||||||
|
@ -137,7 +137,7 @@ class MetricJson {
|
|||||||
p99_9 = s.get999thPercentile();
|
p99_9 = s.get999thPercentile();
|
||||||
|
|
||||||
min = (double) s.getMin();
|
min = (double) s.getMin();
|
||||||
avg = (double) s.getMean();
|
avg = s.getMean();
|
||||||
max = (double) s.getMax();
|
max = (double) s.getMax();
|
||||||
sum = s.getMean() * m.getCount();
|
sum = s.getMean() * m.getCount();
|
||||||
std_dev = s.getStdDev();
|
std_dev = s.getStdDev();
|
||||||
|
@ -51,10 +51,9 @@ class OperatingSystemMXBeanProvider {
|
|||||||
private OperatingSystemMXBeanProvider(OperatingSystemMXBean sys)
|
private OperatingSystemMXBeanProvider(OperatingSystemMXBean sys)
|
||||||
throws ReflectiveOperationException {
|
throws ReflectiveOperationException {
|
||||||
this.sys = sys;
|
this.sys = sys;
|
||||||
getProcessCpuTime = sys.getClass().getMethod("getProcessCpuTime", new Class<?>[] {});
|
getProcessCpuTime = sys.getClass().getMethod("getProcessCpuTime");
|
||||||
getProcessCpuTime.setAccessible(true);
|
getProcessCpuTime.setAccessible(true);
|
||||||
getOpenFileDescriptorCount =
|
getOpenFileDescriptorCount = sys.getClass().getMethod("getOpenFileDescriptorCount");
|
||||||
sys.getClass().getMethod("getOpenFileDescriptorCount", new Class<?>[] {});
|
|
||||||
getOpenFileDescriptorCount.setAccessible(true);
|
getOpenFileDescriptorCount.setAccessible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public class InitLabels implements InitStep {
|
|||||||
KEY_LABEL,
|
KEY_LABEL,
|
||||||
LABEL_VERIFIED,
|
LABEL_VERIFIED,
|
||||||
KEY_VALUE,
|
KEY_VALUE,
|
||||||
Arrays.asList(new String[] {"-1 Fails", "0 No score", "+1 Verified"}));
|
Arrays.asList("-1 Fails", "0 No score", "+1 Verified"));
|
||||||
cfg.setBoolean(KEY_LABEL, LABEL_VERIFIED, KEY_COPY_ALL_SCORES_IF_NO_CODE_CHANGE, true);
|
cfg.setBoolean(KEY_LABEL, LABEL_VERIFIED, KEY_COPY_ALL_SCORES_IF_NO_CODE_CHANGE, true);
|
||||||
allProjectsConfig.save("Configure 'Verified' label");
|
allProjectsConfig.save("Configure 'Verified' label");
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ public final class PatchSet {
|
|||||||
while (true) {
|
while (true) {
|
||||||
int idx = joinedGroups.indexOf(',', i);
|
int idx = joinedGroups.indexOf(',', i);
|
||||||
if (idx < 0) {
|
if (idx < 0) {
|
||||||
groups.add(joinedGroups.substring(i, joinedGroups.length()));
|
groups.add(joinedGroups.substring(i));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
groups.add(joinedGroups.substring(i, idx));
|
groups.add(joinedGroups.substring(i, idx));
|
||||||
|
@ -432,7 +432,7 @@ public class RefNames {
|
|||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Integer.valueOf(name.substring(i, name.length()));
|
return Integer.valueOf(name.substring(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static StringBuilder newStringBuilder() {
|
private static StringBuilder newStringBuilder() {
|
||||||
|
@ -96,13 +96,13 @@ public class IdentifiedUser extends CurrentUser {
|
|||||||
accountCache,
|
accountCache,
|
||||||
groupBackend,
|
groupBackend,
|
||||||
disableReverseDnsLookup,
|
disableReverseDnsLookup,
|
||||||
Providers.of((SocketAddress) null),
|
Providers.of(null),
|
||||||
state,
|
state,
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentifiedUser create(Account.Id id) {
|
public IdentifiedUser create(Account.Id id) {
|
||||||
return create((SocketAddress) null, id);
|
return create(null, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) {
|
public IdentifiedUser create(SocketAddress remotePeer, Account.Id id) {
|
||||||
|
@ -83,7 +83,6 @@ import org.eclipse.jgit.errors.MissingObjectException;
|
|||||||
import org.eclipse.jgit.errors.NoMergeBaseException;
|
import org.eclipse.jgit.errors.NoMergeBaseException;
|
||||||
import org.eclipse.jgit.errors.NoMergeBaseException.MergeBaseFailureReason;
|
import org.eclipse.jgit.errors.NoMergeBaseException.MergeBaseFailureReason;
|
||||||
import org.eclipse.jgit.errors.RevisionSyntaxException;
|
import org.eclipse.jgit.errors.RevisionSyntaxException;
|
||||||
import org.eclipse.jgit.lib.AnyObjectId;
|
|
||||||
import org.eclipse.jgit.lib.CommitBuilder;
|
import org.eclipse.jgit.lib.CommitBuilder;
|
||||||
import org.eclipse.jgit.lib.Config;
|
import org.eclipse.jgit.lib.Config;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
@ -624,7 +623,7 @@ public class MergeUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try (ObjectInserter ins = new InMemoryInserter(repo)) {
|
try (ObjectInserter ins = new InMemoryInserter(repo)) {
|
||||||
return newThreeWayMerger(ins, repo.getConfig()).merge(new AnyObjectId[] {mergeTip, toMerge});
|
return newThreeWayMerger(ins, repo.getConfig()).merge(mergeTip, toMerge);
|
||||||
} catch (LargeObjectException e) {
|
} catch (LargeObjectException e) {
|
||||||
logger.atWarning().log("Cannot merge due to LargeObjectException: %s", toMerge.name());
|
logger.atWarning().log("Cannot merge due to LargeObjectException: %s", toMerge.name());
|
||||||
return false;
|
return false;
|
||||||
@ -722,7 +721,7 @@ public class MergeUtil {
|
|||||||
throws IntegrationException {
|
throws IntegrationException {
|
||||||
ThreeWayMerger m = newThreeWayMerger(inserter, repoConfig);
|
ThreeWayMerger m = newThreeWayMerger(inserter, repoConfig);
|
||||||
try {
|
try {
|
||||||
if (m.merge(new AnyObjectId[] {mergeTip, n})) {
|
if (m.merge(mergeTip, n)) {
|
||||||
return writeMergeCommit(
|
return writeMergeCommit(
|
||||||
author, committer, rw, inserter, destBranch, mergeTip, m.getResultTreeId(), n);
|
author, committer, rw, inserter, destBranch, mergeTip, m.getResultTreeId(), n);
|
||||||
}
|
}
|
||||||
|
@ -407,7 +407,7 @@ public class WorkQueue {
|
|||||||
new Supplier<Long>() {
|
new Supplier<Long>() {
|
||||||
@Override
|
@Override
|
||||||
public Long get() {
|
public Long get() {
|
||||||
return (long) getTaskCount();
|
return getTaskCount();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
metrics.newCallbackMetric(
|
metrics.newCallbackMetric(
|
||||||
@ -419,7 +419,7 @@ public class WorkQueue {
|
|||||||
new Supplier<Long>() {
|
new Supplier<Long>() {
|
||||||
@Override
|
@Override
|
||||||
public Long get() {
|
public Long get() {
|
||||||
return (long) getCompletedTaskCount();
|
return getCompletedTaskCount();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -674,7 +674,7 @@ public class WorkQueue {
|
|||||||
for (Field innerField : innerObj.getClass().getDeclaredFields()) {
|
for (Field innerField : innerObj.getClass().getDeclaredFields()) {
|
||||||
if (innerField.getType().isAssignableFrom(Callable.class)) {
|
if (innerField.getType().isAssignableFrom(Callable.class)) {
|
||||||
innerField.setAccessible(true);
|
innerField.setAccessible(true);
|
||||||
return ((Callable<?>) innerField.get(innerObj)).toString();
|
return innerField.get(innerObj).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,7 +297,7 @@ public class ChangeField {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Long l = Longs.tryParse(v.substring(i2 + 1, v.length()));
|
Long l = Longs.tryParse(v.substring(i2 + 1));
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
logger.atWarning().log(
|
logger.atWarning().log(
|
||||||
"Failed to parse timestamp of reviewer field from change %s: %s", changeId.get(), v);
|
"Failed to parse timestamp of reviewer field from change %s: %s", changeId.get(), v);
|
||||||
@ -350,7 +350,7 @@ public class ChangeField {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Long l = Longs.tryParse(v.substring(i2 + 1, v.length()));
|
Long l = Longs.tryParse(v.substring(i2 + 1));
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
logger.atWarning().log(
|
logger.atWarning().log(
|
||||||
"Failed to parse timestamp of reviewer by email field from change %s: %s",
|
"Failed to parse timestamp of reviewer by email field from change %s: %s",
|
||||||
|
@ -124,7 +124,7 @@ public class MailUtil {
|
|||||||
return Pattern.compile(".*");
|
return Pattern.compile(".*");
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder("");
|
StringBuilder sb = new StringBuilder();
|
||||||
for (String domain : domains) {
|
for (String domain : domains) {
|
||||||
String quoted = "\\Q" + domain.replace("\\E", "\\E\\\\E\\Q") + "\\E|";
|
String quoted = "\\Q" + domain.replace("\\E", "\\E\\\\E\\Q") + "\\E|";
|
||||||
sb.append(quoted.replace("*", "\\E.*\\Q"));
|
sb.append(quoted.replace("*", "\\E.*\\Q"));
|
||||||
|
@ -33,7 +33,7 @@ public class NoteDbUtil {
|
|||||||
String email = ident.getEmailAddress();
|
String email = ident.getEmailAddress();
|
||||||
int at = email.indexOf('@');
|
int at = email.indexOf('@');
|
||||||
if (at >= 0) {
|
if (at >= 0) {
|
||||||
String host = email.substring(at + 1, email.length());
|
String host = email.substring(at + 1);
|
||||||
if (host.equals(serverId)) {
|
if (host.equals(serverId)) {
|
||||||
Integer id = Ints.tryParse(email.substring(0, at));
|
Integer id = Ints.tryParse(email.substring(0, at));
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
@ -97,11 +97,7 @@ public class PRED_commit_edits_2 extends Predicate.P2 {
|
|||||||
|
|
||||||
if (fileRegex.matcher(newName).find()
|
if (fileRegex.matcher(newName).find()
|
||||||
|| (oldName != null && fileRegex.matcher(oldName).find())) {
|
|| (oldName != null && fileRegex.matcher(oldName).find())) {
|
||||||
// This cast still seems to be needed on JDK 8 as workaround for:
|
List<Edit> edits = entry.getEdits();
|
||||||
// https://bugs.openjdk.java.net/browse/JDK-8039214
|
|
||||||
@SuppressWarnings("cast")
|
|
||||||
List<Edit> edits = (List<Edit>) entry.getEdits();
|
|
||||||
|
|
||||||
if (edits.isEmpty()) {
|
if (edits.isEmpty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public class GitmodulesIT extends AbstractDaemonTest {
|
|||||||
.commit()
|
.commit()
|
||||||
.insertChangeId()
|
.insertChangeId()
|
||||||
.message("subject: adding new subscription")
|
.message("subject: adding new subscription")
|
||||||
.add(".gitmodules", config.toText().toString())
|
.add(".gitmodules", config.toText())
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
exception.expectMessage(expectedErrorMessage);
|
exception.expectMessage(expectedErrorMessage);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user