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,8 +226,7 @@ class LinuxWatchService
} }
// no modifiers supported at this time // no modifiers supported at this time
if (modifiers.length > 0) { for (WatchEvent.Modifier modifier : modifiers) {
for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null) if (modifier == null)
return new NullPointerException(); return new NullPointerException();
if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) && if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
@ -236,7 +235,6 @@ class LinuxWatchService
return new UnsupportedOperationException("Modifier not supported"); return new UnsupportedOperationException("Modifier not supported");
} }
} }
}
// check file is directory // check file is directory
UnixFileAttributes attrs = null; UnixFileAttributes attrs = null;

View file

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

View file

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

View file

@ -119,8 +119,7 @@ class PollingWatchService
// Extended modifiers may be used to specify the sensitivity level // Extended modifiers may be used to specify the sensitivity level
int sensitivity = DEFAULT_POLLING_INTERVAL; int sensitivity = DEFAULT_POLLING_INTERVAL;
if (modifiers.length > 0) { for (WatchEvent.Modifier modifier : modifiers) {
for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null) if (modifier == null)
throw new NullPointerException(); throw new NullPointerException();
@ -134,7 +133,6 @@ class PollingWatchService
throw new UnsupportedOperationException("Modifier not supported"); throw new UnsupportedOperationException("Modifier not supported");
} }
} }
}
// check if watch service is closed // check if watch service is closed
if (!isOpen()) if (!isOpen())

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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; int selectableCount = 0;
// Double-check that all the list selections are valid for this mode // Double-check that all the list selections are valid for this mode
// Directories can be selected in the list regardless of mode // Directories can be selected in the list regardless of mode
if (rows.length > 0) {
for (final int element : rows) { for (final int element : rows) {
if (isSelectableForMode(chooser, (File)fFileList.getValueAt(element, 0))) selectableCount++; if (isSelectableForMode(chooser, (File) fFileList.getValueAt(element, 0))) selectableCount++;
}
} }
if (selectableCount > 0) { if (selectableCount > 0) {
final File[] files = new File[selectableCount]; 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -89,12 +89,10 @@ public final class Assumptions implements Iterable<Assumptions.Assumption> {
public void recordTo(Assumptions target) { public void recordTo(Assumptions target) {
assert canRecordTo(target); assert canRecordTo(target);
if (assumptions.length > 0) {
for (Assumption assumption : assumptions) { for (Assumption assumption : assumptions) {
target.record(assumption); target.record(assumption);
} }
} }
}
@Override @Override
public String toString() { public String toString() {

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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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); Messages.NOTIFICATIONS, null);
notifications.setUserObject(notificationsUO); notifications.setUserObject(notificationsUO);
node.insert(notifications, childIndex++); node.insert(notifications, childIndex++);
if (ni != null && ni.length > 0) { if (ni != null) {
for (MBeanNotificationInfo mbni : ni) { for (MBeanNotificationInfo mbni : ni) {
DefaultMutableTreeNode notification = DefaultMutableTreeNode notification =
new DefaultMutableTreeNode(); new DefaultMutableTreeNode();

View file

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