8346671: java/nio/file/Files/probeContentType/Basic.java fails on Windows 2025

Backport-of: 2e00816ac3
This commit is contained in:
Goetz Lindenmaier
2025-02-11 13:49:24 +00:00
committed by Vitaly Provodin
parent 2b82cb4c9b
commit 748ed353fc

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2023, 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
@@ -40,6 +40,7 @@ import java.util.stream.Stream;
import jdk.internal.util.OperatingSystem;
import jdk.internal.util.OSVersion;
import jdk.internal.util.StaticProperty;
/**
* Uses Files.probeContentType to probe html file, custom file type, and minimal
@@ -83,7 +84,7 @@ public class Basic {
if (!expected.equals(actual)) {
if (!OperatingSystem.isWindows()) {
Path userMimeTypes =
Path.of(System.getProperty("user.home"), ".mime.types");
Path.of(StaticProperty.userHome(), ".mime.types");
checkMimeTypesFile(userMimeTypes);
Path etcMimeTypes = Path.of("/etc/mime.types");
@@ -188,9 +189,10 @@ public class Basic {
exTypes.add(new ExType("xlsx", List.of("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")));
exTypes.add(new ExType("wasm", List.of("application/wasm")));
// extensions with content type that differs on Windows 11+
// extensions with content type that differs on Windows 11+ and
// Windows Server 2025
if (OperatingSystem.isWindows() &&
(System.getProperty("os.name").endsWith("11") ||
(StaticProperty.osName().matches("^.*[11|2025]$") ||
new OSVersion(10, 0).compareTo(OSVersion.current()) > 0)) {
System.out.println("Windows 11+ detected: using different types");
exTypes.add(new ExType("bz2", List.of("application/bz2", "application/x-bzip2", "application/x-bzip", "application/x-compressed")));