mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-15 13:49:42 +02:00
8364761: (aio) AsynchronousChannelGroup.execute doesn't check null command
Reviewed-by: alanb, vyazici
This commit is contained in:
parent
958383d69c
commit
8cd79752c6
2 changed files with 56 additions and 28 deletions
|
@ -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.
|
* 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
|
||||||
|
@ -30,6 +30,7 @@ import java.nio.channels.AsynchronousChannelGroup;
|
||||||
import java.nio.channels.spi.AsynchronousChannelProvider;
|
import java.nio.channels.spi.AsynchronousChannelProvider;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
@ -299,6 +300,7 @@ abstract class AsynchronousChannelGroupImpl
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void execute(Runnable task) {
|
public final void execute(Runnable task) {
|
||||||
|
Objects.requireNonNull(task, "task");
|
||||||
executeOnPooledThread(task);
|
executeOnPooledThread(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
* 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
|
||||||
|
@ -23,49 +23,75 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @bug 4607272
|
* @bug 4607272 8364761
|
||||||
* @summary tests tasks can be submitted to a channel group's thread pool.
|
* @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.nio.channels.AsynchronousChannelGroup;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
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 {
|
public class AsExecutor {
|
||||||
|
private static ThreadFactory factory;
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
@BeforeAll
|
||||||
// create channel groups
|
public static void createThreadFactory() {
|
||||||
ThreadFactory factory = Executors.defaultThreadFactory();
|
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 {
|
try {
|
||||||
// execute simple tasks
|
Executor executor = (Executor)group;
|
||||||
testSimpleTask(group1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
testSimpleTask(group2);
|
executor.execute(new Runnable() {
|
||||||
testSimpleTask(group3);
|
public void run() {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
latch.await();
|
||||||
} finally {
|
} finally {
|
||||||
group1.shutdown();
|
group.shutdown();
|
||||||
group2.shutdown();
|
|
||||||
group3.shutdown();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testSimpleTask(AsynchronousChannelGroup group) throws Exception {
|
@ParameterizedTest
|
||||||
|
@MethodSource("channelGroups")
|
||||||
|
public void nullTask(AsynchronousChannelGroup group) {
|
||||||
Executor executor = (Executor)group;
|
Executor executor = (Executor)group;
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
try {
|
||||||
executor.execute(new Runnable() {
|
assertThrows(NullPointerException.class,
|
||||||
public void run() {
|
() -> executor.execute(null));
|
||||||
latch.countDown();
|
} finally {
|
||||||
}
|
group.shutdown();
|
||||||
});
|
}
|
||||||
latch.await();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue