This is an automated email from the ASF dual-hosted git repository.

trohrmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new fda7e5f  [FLINK-12636] Check if proper JAR file in 
JobWithJars#checkJarFile
fda7e5f is described below

commit fda7e5f97c28ff3c020070523812590f34f98ea3
Author: tianchen <niki...@alibaba-inc.com>
AuthorDate: Mon May 27 16:36:46 2019 +0800

    [FLINK-12636] Check if proper JAR file in JobWithJars#checkJarFile
    
    This closes #8552.
---
 .../java/org/apache/flink/client/program/JobWithJars.java  | 14 ++++++++++----
 .../org/apache/flink/client/program/PackagedProgram.java   |  2 +-
 .../runtime/webmonitor/handlers/JarRunHandlerTest.java     |  4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git 
a/flink-clients/src/main/java/org/apache/flink/client/program/JobWithJars.java 
b/flink-clients/src/main/java/org/apache/flink/client/program/JobWithJars.java
index 768de87..6e1bf99 100644
--- 
a/flink-clients/src/main/java/org/apache/flink/client/program/JobWithJars.java
+++ 
b/flink-clients/src/main/java/org/apache/flink/client/program/JobWithJars.java
@@ -28,6 +28,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.jar.JarFile;
 
 /**
  * A JobWithJars is a Flink dataflow plan, together with a bunch of JAR files 
that contain
@@ -114,15 +115,20 @@ public class JobWithJars {
                try {
                        jarFile = new File(jar.toURI());
                } catch (URISyntaxException e) {
-                       throw new IOException("JAR file path is invalid '" + 
jar + "'");
+                       throw new IOException("JAR file path is invalid '" + 
jar + '\'');
                }
                if (!jarFile.exists()) {
-                       throw new IOException("JAR file does not exist '" + 
jarFile.getAbsolutePath() + "'");
+                       throw new IOException("JAR file does not exist '" + 
jarFile.getAbsolutePath() + '\'');
                }
                if (!jarFile.canRead()) {
-                       throw new IOException("JAR file can't be read '" + 
jarFile.getAbsolutePath() + "'");
+                       throw new IOException("JAR file can't be read '" + 
jarFile.getAbsolutePath() + '\'');
+               }
+
+               try (JarFile ignored = new JarFile(jarFile)) {
+                       // verify that we can open the Jar file
+               } catch (IOException e) {
+                       throw new IOException("Error while opening jar file '" 
+ jarFile.getAbsolutePath() + '\'', e);
                }
-               // TODO: Check if proper JAR file
        }
 
        public static ClassLoader buildUserCodeClassLoader(List<URL> jars, 
List<URL> classpaths, ClassLoader parent) {
diff --git 
a/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java
 
b/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java
index cc5c960..3218393 100644
--- 
a/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java
+++ 
b/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java
@@ -820,7 +820,7 @@ public class PackagedProgram {
                        JobWithJars.checkJarFile(jarfile);
                }
                catch (IOException e) {
-                       throw new ProgramInvocationException(e.getMessage());
+                       throw new ProgramInvocationException(e.getMessage(), e);
                }
                catch (Throwable t) {
                        throw new ProgramInvocationException("Cannot access jar 
file" + (t.getMessage() == null ? "." : ": " + t.getMessage()), t);
diff --git 
a/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JarRunHandlerTest.java
 
b/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JarRunHandlerTest.java
index 1b23635..b4182c7 100644
--- 
a/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JarRunHandlerTest.java
+++ 
b/flink-runtime-web/src/test/java/org/apache/flink/runtime/webmonitor/handlers/JarRunHandlerTest.java
@@ -93,10 +93,10 @@ public class JarRunHandlerTest extends TestLogger {
                                                // implies the job was actually 
submitted
                                                
assertTrue(expected.get().getMessage().contains("ProgramInvocationException"));
                                                // original cause is preserved 
in stack trace
-                                               
assertThat(expected.get().getMessage(), containsString("ZipException"));
+                                               
assertThat(expected.get().getMessage(), containsString("ZipException: zip file 
is empty"));
                                                // implies the jar was 
registered for the job graph (otherwise the jar name would not occur in the 
exception)
                                                // implies the jar was uploaded 
(otherwise the file would not be found at all)
-                                               
assertTrue(expected.get().getMessage().contains("empty.jar'. zip file is 
empty"));
+                                               
assertTrue(expected.get().getMessage().contains("empty.jar"));
                                        } else {
                                                throw e;
                                        }

Reply via email to