From fb87831bf8ffccc27c4f42e72d0beac4ef38a741 Mon Sep 17 00:00:00 2001 From: Harsha Wardhana B Date: Fri, 12 May 2017 18:21:13 +0530 Subject: [PATCH] 8176055: JMX diagnostic improvements Reviewed-by: dfuchs, mchung, ahgross, rhalade, jwilhelm --- .../com/sun/management/HotSpotDiagnosticMXBean.java | 5 +++-- .../sun/management/internal/HotSpotDiagnostic.java | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/jdk/src/jdk.management/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java b/jdk/src/jdk.management/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java index 40d79a2800ca7..c79d511b471ed 100644 --- a/jdk/src/jdk.management/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java +++ b/jdk/src/jdk.management/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2017, 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 @@ -61,9 +61,10 @@ public interface HotSpotDiagnosticMXBean extends PlatformManagedObject { * @param outputFile the system-dependent filename * @param live if {@code true} dump only live objects * i.e. objects that are reachable from others - * @throws IOException if the {@code outputFile} + * @throws IOException if the {@code outputFile} already exists, * cannot be created, opened, or written to. * @throws UnsupportedOperationException if this operation is not supported. + * @throws IllegalArgumentException if {@code outputFile} does not end with ".hprof" suffix. * @throws NullPointerException if {@code outputFile} is {@code null}. * @throws SecurityException * If a security manager exists and its {@link diff --git a/jdk/src/jdk.management/share/classes/com/sun/management/internal/HotSpotDiagnostic.java b/jdk/src/jdk.management/share/classes/com/sun/management/internal/HotSpotDiagnostic.java index 5b9d8efdafced..4edf6ad2e3605 100644 --- a/jdk/src/jdk.management/share/classes/com/sun/management/internal/HotSpotDiagnostic.java +++ b/jdk/src/jdk.management/share/classes/com/sun/management/internal/HotSpotDiagnostic.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2017, 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 @@ -22,7 +22,6 @@ * or visit www.oracle.com if you need additional information or have any * questions. */ - package com.sun.management.internal; import java.io.IOException; @@ -32,6 +31,8 @@ import com.sun.management.HotSpotDiagnosticMXBean; import com.sun.management.VMOption; +import java.security.AccessController; +import java.security.PrivilegedAction; import sun.management.Util; /** @@ -43,6 +44,14 @@ public HotSpotDiagnostic() { @Override public void dumpHeap(String outputFile, boolean live) throws IOException { + + String propertyName = "jdk.management.heapdump.allowAnyFileSuffix"; + PrivilegedAction pa = () -> Boolean.parseBoolean(System.getProperty(propertyName, "false")); + boolean allowAnyFileSuffix = AccessController.doPrivileged(pa); + if (!allowAnyFileSuffix && !outputFile.endsWith(".hprof")) { + throw new IllegalArgumentException("heapdump file must have .hprof extention"); + } + SecurityManager security = System.getSecurityManager(); if (security != null) { security.checkWrite(outputFile);