提交 2528d52d 编写于 作者: S serb

8191239: Improve desktop file usage

Reviewed-by: prr, rhalade, aghaisas
上级 14d95380
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2018, 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
...@@ -202,15 +202,11 @@ public class Desktop { ...@@ -202,15 +202,11 @@ public class Desktop {
* @throws NullPointerException if file is null * @throws NullPointerException if file is null
* @throws IllegalArgumentException if file doesn't exist * @throws IllegalArgumentException if file doesn't exist
*/ */
private static void checkFileValidation(File file){ private static void checkFileValidation(File file) {
if (file == null) throw new NullPointerException("File must not be null");
if (!file.exists()) { if (!file.exists()) {
throw new IllegalArgumentException("The file: " throw new IllegalArgumentException("The file: "
+ file.getPath() + " doesn't exist."); + file.getPath() + " doesn't exist.");
} }
file.canRead();
} }
/** /**
...@@ -264,6 +260,7 @@ public class Desktop { ...@@ -264,6 +260,7 @@ public class Desktop {
* @see java.awt.AWTPermission * @see java.awt.AWTPermission
*/ */
public void open(File file) throws IOException { public void open(File file) throws IOException {
file = new File(file.getPath());
checkAWTPermission(); checkAWTPermission();
checkExec(); checkExec();
checkActionSupport(Action.OPEN); checkActionSupport(Action.OPEN);
...@@ -295,6 +292,7 @@ public class Desktop { ...@@ -295,6 +292,7 @@ public class Desktop {
* @see java.awt.AWTPermission * @see java.awt.AWTPermission
*/ */
public void edit(File file) throws IOException { public void edit(File file) throws IOException {
file = new File(file.getPath());
checkAWTPermission(); checkAWTPermission();
checkExec(); checkExec();
checkActionSupport(Action.EDIT); checkActionSupport(Action.EDIT);
...@@ -325,6 +323,7 @@ public class Desktop { ...@@ -325,6 +323,7 @@ public class Desktop {
* allowed to create a subprocess * allowed to create a subprocess
*/ */
public void print(File file) throws IOException { public void print(File file) throws IOException {
file = new File(file.getPath());
checkExec(); checkExec();
SecurityManager sm = System.getSecurityManager(); SecurityManager sm = System.getSecurityManager();
if (sm != null) { if (sm != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册