Skip to content

Commit e3c6cf8

Browse files
Sergey TsypanovTheShermanTanker
authored andcommitted
8298380: Clean up redundant array length checks in JDK code base
Reviewed-by: dholmes, amenkov, serb, vtewari
1 parent 33d955a commit e3c6cf8

File tree

8 files changed

+38
-52
lines changed

8 files changed

+38
-52
lines changed

src/java.base/linux/classes/sun/nio/fs/LinuxWatchService.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,13 @@ Object implRegister(Path obj,
226226
}
227227

228228
// no modifiers supported at this time
229-
if (modifiers.length > 0) {
230-
for (WatchEvent.Modifier modifier: modifiers) {
231-
if (modifier == null)
232-
return new NullPointerException();
233-
if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
234-
!ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
235-
!ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
236-
return new UnsupportedOperationException("Modifier not supported");
237-
}
229+
for (WatchEvent.Modifier modifier : modifiers) {
230+
if (modifier == null)
231+
return new NullPointerException();
232+
if (!ExtendedOptions.SENSITIVITY_HIGH.matches(modifier) &&
233+
!ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier) &&
234+
!ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
235+
return new UnsupportedOperationException("Modifier not supported");
238236
}
239237
}
240238

src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,11 @@ public FileSystem newFileSystem(Path path, Map<String,?> env)
411411
public InputStream newInputStream(Path path, OpenOption... options)
412412
throws IOException
413413
{
414-
if (options.length > 0) {
415-
for (OpenOption opt: options) {
416-
// All OpenOption values except for APPEND and WRITE are allowed
417-
if (opt == StandardOpenOption.APPEND ||
418-
opt == StandardOpenOption.WRITE)
419-
throw new UnsupportedOperationException("'" + opt + "' not allowed");
420-
}
414+
for (OpenOption opt : options) {
415+
// All OpenOption values except for APPEND and WRITE are allowed
416+
if (opt == StandardOpenOption.APPEND ||
417+
opt == StandardOpenOption.WRITE)
418+
throw new UnsupportedOperationException("'" + opt + "' not allowed");
421419
}
422420
ReadableByteChannel rbc = Files.newByteChannel(path, options);
423421
if (rbc instanceof FileChannelImpl) {

src/java.base/share/classes/jdk/internal/jrtfs/JrtPath.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,9 @@ final void createDirectory(FileAttribute<?>... attrs)
627627
}
628628

629629
final InputStream newInputStream(OpenOption... options) throws IOException {
630-
if (options.length > 0) {
631-
for (OpenOption opt : options) {
632-
if (opt != READ) {
633-
throw new UnsupportedOperationException("'" + opt + "' not allowed");
634-
}
630+
for (OpenOption opt : options) {
631+
if (opt != READ) {
632+
throw new UnsupportedOperationException("'" + opt + "' not allowed");
635633
}
636634
}
637635
return jrtfs.newInputStream(this);

src/java.base/share/classes/sun/nio/fs/PollingWatchService.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,18 @@ WatchKey register(final Path path,
119119

120120
// Extended modifiers may be used to specify the sensitivity level
121121
int sensitivity = DEFAULT_POLLING_INTERVAL;
122-
if (modifiers.length > 0) {
123-
for (WatchEvent.Modifier modifier: modifiers) {
124-
if (modifier == null)
125-
throw new NullPointerException();
126-
127-
if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
128-
sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter();
129-
} else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) {
130-
sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter();
131-
} else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
132-
sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter();
133-
} else {
134-
throw new UnsupportedOperationException("Modifier not supported");
135-
}
122+
for (WatchEvent.Modifier modifier : modifiers) {
123+
if (modifier == null)
124+
throw new NullPointerException();
125+
126+
if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
127+
sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter();
128+
} else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) {
129+
sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter();
130+
} else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
131+
sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter();
132+
} else {
133+
throw new UnsupportedOperationException("Modifier not supported");
136134
}
137135
}
138136

src/java.desktop/macosx/classes/com/apple/laf/AquaFileChooserUI.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -653,10 +653,8 @@ public void valueChanged(final ListSelectionEvent e) {
653653
int selectableCount = 0;
654654
// Double-check that all the list selections are valid for this mode
655655
// Directories can be selected in the list regardless of mode
656-
if (rows.length > 0) {
657-
for (final int element : rows) {
658-
if (isSelectableForMode(chooser, (File)fFileList.getValueAt(element, 0))) selectableCount++;
659-
}
656+
for (final int element : rows) {
657+
if (isSelectableForMode(chooser, (File) fFileList.getValueAt(element, 0))) selectableCount++;
660658
}
661659
if (selectableCount > 0) {
662660
final File[] files = new File[selectableCount];

src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.meta/src/jdk/vm/ci/meta/Assumptions.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -89,10 +89,8 @@ public boolean canRecordTo(Assumptions target) {
8989
public void recordTo(Assumptions target) {
9090
assert canRecordTo(target);
9191

92-
if (assumptions.length > 0) {
93-
for (Assumption assumption : assumptions) {
94-
target.record(assumption);
95-
}
92+
for (Assumption assumption : assumptions) {
93+
target.record(assumption);
9694
}
9795
}
9896

src/jdk.jconsole/share/classes/sun/tools/jconsole/inspector/XTree.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -649,7 +649,7 @@ private void addMBeanInfoNodes(
649649
Messages.NOTIFICATIONS, null);
650650
notifications.setUserObject(notificationsUO);
651651
node.insert(notifications, childIndex++);
652-
if (ni != null && ni.length > 0) {
652+
if (ni != null) {
653653
for (MBeanNotificationInfo mbni : ni) {
654654
DefaultMutableTreeNode notification =
655655
new DefaultMutableTreeNode();

src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipPath.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,9 @@ void createDirectory(FileAttribute<?>... attrs)
744744

745745
InputStream newInputStream(OpenOption... options) throws IOException
746746
{
747-
if (options.length > 0) {
748-
for (OpenOption opt : options) {
749-
if (opt != READ)
750-
throw new UnsupportedOperationException("'" + opt + "' not allowed");
751-
}
747+
for (OpenOption opt : options) {
748+
if (opt != READ)
749+
throw new UnsupportedOperationException("'" + opt + "' not allowed");
752750
}
753751
return zfs.newInputStream(getResolvedPath());
754752
}

0 commit comments

Comments
 (0)