< prev index next >

src/jdk.jlink/share/classes/jdk/tools/jimage/JImageTask.java

Print this page

        

@@ -378,13 +378,11 @@
     }
 
     private void iterate(JImageAction jimageAction,
             ModuleAction moduleAction,
             ResourceAction resourceAction) throws IOException, BadArgs {
-        if (options.jimages.isEmpty()) {
-            throw TASK_HELPER.newBadArgs("err.no.jimage");
-        }
+        validateOptions();
 
         for (File file : options.jimages) {
             if (!file.exists() || !file.isFile()) {
                 throw TASK_HELPER.newBadArgs("err.not.a.jimage", file.getName());
             }

@@ -433,10 +431,29 @@
                 }
             }
         }
     }
 
+    private void validateOptions() throws BadArgs {
+        if (options.jimages.isEmpty()) {
+            throw TASK_HELPER.newBadArgs("err.no.jimage");
+        }
+
+        if (options.task == Task.EXTRACT) {
+            File extractTargetDir = new File(options.directory);
+            if (extractTargetDir.exists()) {
+                if (extractTargetDir.isDirectory()) {
+                    if (extractTargetDir.listFiles().length > 0) {
+                        throw TASK_HELPER.newBadArgs("err.not.an.empty.dir", options.directory);
+                    }
+                } else {
+                    throw TASK_HELPER.newBadArgs("err.not.a.dir", options.directory);
+                }
+            }
+        }
+    }
+
     private boolean run() throws Exception, BadArgs {
         switch (options.task) {
             case EXTRACT:
                 iterate(null, null, this::extract);
                 break;
< prev index next >