8298380: Clean up redundant array length checks in JDK code base

Reviewed-by: dholmes, amenkov, serb, vtewari
This commit is contained in:
Sergey Tsypanov 2022-12-09 12:50:55 +00:00 committed by Julian Waters
parent 33d955ad6e
commit e3c6cf8eaf
8 changed files with 37 additions and 51 deletions

View File

@ -226,15 +226,13 @@ class LinuxWatchService
}
// no modifiers supported at this time
if (modifiers.length > 0) {
for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null)
return new NullPointerException();
if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
!ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
!ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
return new UnsupportedOperationException("Modifier not supported");
}
for (WatchEvent.Modifier modifier : modifiers) {
if (modifier == null)
return new NullPointerException();
if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
!ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
!ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
return new UnsupportedOperationException("Modifier not supported");
}
}

View File

@ -411,13 +411,11 @@ public abstract class FileSystemProvider {
public InputStream newInputStream(Path path, OpenOption... options)
throws IOException
{
if (options.length > 0) {
for (OpenOption opt: options) {
// All OpenOption values except for APPEND and WRITE are allowed
if (opt == StandardOpenOption.APPEND ||
opt == StandardOpenOption.WRITE)
throw new UnsupportedOperationException("'" + opt + "' not allowed");
}
for (OpenOption opt : options) {
// All OpenOption values except for APPEND and WRITE are allowed
if (opt == StandardOpenOption.APPEND ||
opt == StandardOpenOption.WRITE)
throw new UnsupportedOperationException("'" + opt + "' not allowed");
}
ReadableByteChannel rbc = Files.newByteChannel(path, options);
if (rbc instanceof FileChannelImpl) {

View File

@ -627,11 +627,9 @@ final class JrtPath implements Path {
}
final InputStream newInputStream(OpenOption... options) throws IOException {
if (options.length > 0) {
for (OpenOption opt : options) {
if (opt != READ) {
throw new UnsupportedOperationException("'" + opt + "' not allowed");
}
for (OpenOption opt : options) {
if (opt != READ) {
throw new UnsupportedOperationException("'" + opt + "' not allowed");
}
}
return jrtfs.newInputStream(this);

View File

@ -119,20 +119,18 @@ class PollingWatchService
// Extended modifiers may be used to specify the sensitivity level
int sensitivity = DEFAULT_POLLING_INTERVAL;
if (modifiers.length > 0) {
for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null)
throw new NullPointerException();
for (WatchEvent.Modifier modifier : modifiers) {
if (modifier == null)
throw new NullPointerException();
if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter();
} else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter();
} else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter();
} else {
throw new UnsupportedOperationException("Modifier not supported");
}
if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter();
} else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter();
} else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter();
} else {
throw new UnsupportedOperationException("Modifier not supported");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -653,10 +653,8 @@ public class AquaFileChooserUI extends FileChooserUI {
int selectableCount = 0;
// Double-check that all the list selections are valid for this mode
// Directories can be selected in the list regardless of mode
if (rows.length > 0) {
for (final int element : rows) {
if (isSelectableForMode(chooser, (File)fFileList.getValueAt(element, 0))) selectableCount++;
}
for (final int element : rows) {
if (isSelectableForMode(chooser, (File) fFileList.getValueAt(element, 0))) selectableCount++;
}
if (selectableCount > 0) {
final File[] files = new File[selectableCount];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -89,10 +89,8 @@ public final class Assumptions implements Iterable<Assumptions.Assumption> {
public void recordTo(Assumptions target) {
assert canRecordTo(target);
if (assumptions.length > 0) {
for (Assumption assumption : assumptions) {
target.record(assumption);
}
for (Assumption assumption : assumptions) {
target.record(assumption);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -649,7 +649,7 @@ public class XTree extends JTree {
Messages.NOTIFICATIONS, null);
notifications.setUserObject(notificationsUO);
node.insert(notifications, childIndex++);
if (ni != null && ni.length > 0) {
if (ni != null) {
for (MBeanNotificationInfo mbni : ni) {
DefaultMutableTreeNode notification =
new DefaultMutableTreeNode();

View File

@ -744,11 +744,9 @@ final class ZipPath implements Path {
InputStream newInputStream(OpenOption... options) throws IOException
{
if (options.length > 0) {
for (OpenOption opt : options) {
if (opt != READ)
throw new UnsupportedOperationException("'" + opt + "' not allowed");
}
for (OpenOption opt : options) {
if (opt != READ)
throw new UnsupportedOperationException("'" + opt + "' not allowed");
}
return zfs.newInputStream(getResolvedPath());
}