Skip to content

8364761: (aio) AsynchronousChannelGroup.execute doesn't check null command #26709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2025, 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
Expand Down Expand Up @@ -30,6 +30,7 @@
import java.nio.channels.spi.AsynchronousChannelProvider;
import java.io.IOException;
import java.io.FileDescriptor;
import java.util.Objects;
import java.util.Queue;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down Expand Up @@ -299,6 +300,7 @@ public final boolean awaitTermination(long timeout, TimeUnit unit)
*/
@Override
public final void execute(Runnable task) {
Objects.requireNonNull(task, "task");
executeOnPooledThread(task);
}
}
80 changes: 53 additions & 27 deletions test/jdk/java/nio/channels/AsynchronousChannelGroup/AsExecutor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2025, 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
Expand All @@ -23,49 +23,75 @@

/*
* @test
* @bug 4607272
* @bug 4607272 8364761
* @summary tests tasks can be submitted to a channel group's thread pool.
* @run main AsExecutor
* @run junit AsExecutor
*/

import java.io.IOException;
import java.nio.channels.AsynchronousChannelGroup;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import static org.junit.jupiter.api.Assertions.assertThrows;

public class AsExecutor {
private static ThreadFactory factory;

@BeforeAll
public static void createThreadFactory() {
factory = Executors.defaultThreadFactory();
}

public static void main(String[] args) throws Exception {
// create channel groups
ThreadFactory factory = Executors.defaultThreadFactory();
AsynchronousChannelGroup group1 = AsynchronousChannelGroup
.withFixedThreadPool(5, factory);
AsynchronousChannelGroup group2 = AsynchronousChannelGroup
.withCachedThreadPool(Executors.newCachedThreadPool(factory), 0);
AsynchronousChannelGroup group3 = AsynchronousChannelGroup
.withThreadPool(Executors.newFixedThreadPool(10, factory));
private static Stream<Arguments> channelGroups() throws IOException {
List<Arguments> list = new ArrayList<Arguments>();
list.add(Arguments.of(AsynchronousChannelGroup
.withFixedThreadPool(5, factory)));
list.add(Arguments.of(AsynchronousChannelGroup
.withCachedThreadPool(Executors.newCachedThreadPool(factory), 0)));
list.add(Arguments.of(AsynchronousChannelGroup
.withThreadPool(Executors.newFixedThreadPool(10, factory))));
return list.stream();
}

@ParameterizedTest
@MethodSource("channelGroups")
public void simpleTask(AsynchronousChannelGroup group)
throws InterruptedException
{
try {
// execute simple tasks
testSimpleTask(group1);
testSimpleTask(group2);
testSimpleTask(group3);
Executor executor = (Executor)group;
final CountDownLatch latch = new CountDownLatch(1);
executor.execute(new Runnable() {
public void run() {
latch.countDown();
}
});
latch.await();
} finally {
group1.shutdown();
group2.shutdown();
group3.shutdown();
group.shutdown();
}
}

static void testSimpleTask(AsynchronousChannelGroup group) throws Exception {
@ParameterizedTest
@MethodSource("channelGroups")
public void nullTask(AsynchronousChannelGroup group) {
Executor executor = (Executor)group;
final CountDownLatch latch = new CountDownLatch(1);
executor.execute(new Runnable() {
public void run() {
latch.countDown();
}
});
latch.await();
try {
assertThrows(NullPointerException.class,
() -> executor.execute(null));
} finally {
group.shutdown();
}
}
}