Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259028: ClassCastException when using custom filesystem with wrapper…
… FileChannel impl

Reviewed-by: chegar, alanb, uschindler
  • Loading branch information
mcimadamore committed Jan 11, 2021
1 parent e05f36f commit d60a937e876f1b38a958d96f10791c8d7a1c9277
@@ -876,10 +876,9 @@ static MemorySegment allocateNative(long bytesSize) {
* @param mapMode a file mapping mode, see {@link FileChannel#map(FileChannel.MapMode, long, long)}; the chosen mapping mode
* might affect the behavior of the returned memory mapped segment (see {@link MappedMemorySegments#force(MemorySegment)}).
* @return a new confined mapped memory segment.
* @throws IllegalArgumentException if {@code bytesOffset < 0}.
* @throws IllegalArgumentException if {@code bytesSize < 0}.
* @throws UnsupportedOperationException if an unsupported map mode is specified, or if the {@code path} is associated
* with a provider that does not support creating file channels.
* @throws IllegalArgumentException if {@code bytesOffset < 0}, {@code bytesSize < 0}, or if {@code path} is not associated
* with the default file system.
* @throws UnsupportedOperationException if an unsupported map mode is specified.
* @throws IOException if the specified path does not point to an existing file, or if some other I/O error occurs.
* @throws SecurityException If a security manager is installed and it denies an unspecified permission required by the implementation.
* In the case of the default provider, the {@link SecurityManager#checkRead(String)} method is invoked to check
@@ -34,6 +34,8 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -114,8 +116,13 @@ public static MemorySegment makeMappedSegment(Path path, long bytesOffset, long
Objects.requireNonNull(mapMode);
if (bytesSize < 0) throw new IllegalArgumentException("Requested bytes size must be >= 0.");
if (bytesOffset < 0) throw new IllegalArgumentException("Requested bytes offset must be >= 0.");
try (FileChannelImpl channelImpl = (FileChannelImpl)FileChannel.open(path, openOptions(mapMode))) {
UnmapperProxy unmapperProxy = channelImpl.mapInternal(mapMode, bytesOffset, bytesSize);
FileSystem fs = path.getFileSystem();
if (fs != FileSystems.getDefault() ||
fs.getClass().getModule() != Object.class.getModule()) {
throw new IllegalArgumentException("Unsupported file system");
}
try (FileChannel channelImpl = FileChannel.open(path, openOptions(mapMode))) {
UnmapperProxy unmapperProxy = ((FileChannelImpl)channelImpl).mapInternal(mapMode, bytesOffset, bytesSize);
int modes = defaultAccessModes(bytesSize);
if (mapMode == FileChannel.MapMode.READ_ONLY) {
modes &= ~WRITE;
@@ -47,6 +47,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@@ -513,6 +514,12 @@ public void testMapZeroSize() throws IOException {
}
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void testMapCustomPath() throws IOException {
Path path = Path.of(URI.create("jrt:/"));
MemorySegment.mapFile(path, 0L, 0L, FileChannel.MapMode.READ_WRITE);
}

@Test(dataProvider="resizeOps")
public void testCopyHeapToNative(Consumer<MemorySegment> checker, Consumer<MemorySegment> initializer, SequenceLayout seq) {
checkByteArrayAlignment(seq.elementLayout());

1 comment on commit d60a937

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on d60a937 Jan 11, 2021

Please sign in to comment.