8214070: Analyze and Fix issues reported by Parfait JDK-8200758-branch
authorherrick
Mon, 03 Dec 2018 08:13:19 -0500
branchJDK-8200758-branch
changeset 57052 92cdab03fb81
parent 57040 6a4332753587
child 57053 700a46deb15d
8214070: Analyze and Fix issues reported by Parfait Submitten-by: almatvee Reviewed-by: herrick
src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java
src/jdk.jpackage/share/native/library/common/JavaTypes.cpp
src/jdk.jpackage/share/native/library/common/JavaTypes.h
src/jdk.jpackage/share/native/library/common/OrderedMap.h
src/jdk.jpackage/share/native/library/common/PosixPlatform.cpp
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java	Fri Nov 23 09:12:00 2018 -0500
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java	Mon Dec 03 08:13:19 2018 -0500
@@ -252,8 +252,7 @@
 
         if (mainJar != null) {
             mainJarType = new ModFile(mainJar).getModType();
-        } else if (mainJar == null &&
-                StandardBundlerParam.MODULE.fetchFrom(params) == null) {
+        } else if (StandardBundlerParam.MODULE.fetchFrom(params) == null) {
             // user specified only main class, all jars will be on the classpath
             mainJarType = ModFile.ModType.UnnamedJar;
         }
--- a/src/jdk.jpackage/share/native/library/common/JavaTypes.cpp	Fri Nov 23 09:12:00 2018 -0500
+++ b/src/jdk.jpackage/share/native/library/common/JavaTypes.cpp	Mon Dec 03 08:13:19 2018 -0500
@@ -159,164 +159,3 @@
 void JavaException::Rethrow() {
     FEnv->Throw(FException);
 }
-
-//----------------------------------------------------------------------------
-
-JavaStaticMethod::JavaStaticMethod(JNIEnv *Env, jclass Class, jmethodID Method) {
-    FEnv = Env;
-    FClass = Class;
-    FMethod = Method;
-}
-
-void JavaStaticMethod::CallVoidMethod(int Count, ...) {
-    va_list args;
-    va_start(args, Count);
-    FEnv->CallStaticVoidMethodV(FClass, FMethod, args);
-    va_end(args);
-
-    if (FEnv->ExceptionCheck() == JNI_TRUE) {
-        Messages& messages = Messages::GetInstance();
-        throw JavaException(FEnv, messages.GetMessage(ERROR_INVOKING_METHOD));
-    }
-}
-
-JavaStaticMethod::operator jmethodID () {
-    return FMethod;
-}
-
-//----------------------------------------------------------------------------
-
-JavaMethod::JavaMethod(JNIEnv *Env, jobject Obj, jmethodID Method) {
-    FEnv = Env;
-    FObj = Obj;
-    FMethod = Method;
-}
-
-void JavaMethod::CallVoidMethod(int Count, ...) {
-    va_list args;
-    va_start(args, Count);
-    FEnv->CallVoidMethodV(FObj, FMethod, args);
-    va_end(args);
-
-    if (FEnv->ExceptionCheck() == JNI_TRUE) {
-        Messages& messages = Messages::GetInstance();
-        throw JavaException(FEnv, messages.GetMessage(ERROR_INVOKING_METHOD));
-    }
-}
-
-JavaMethod::operator jmethodID () {
-    return FMethod;
-}
-
-//----------------------------------------------------------------------------
-
-JavaClass::JavaClass(JNIEnv *Env, TString Name) {
-    FEnv = Env;
-    FClassName = Name;
-    FClass = FEnv->FindClass(PlatformString(FClassName));
-
-    if (FClass == NULL || FEnv->ExceptionCheck() == JNI_TRUE) {
-        Messages& messages = Messages::GetInstance();
-        TString message = messages.GetMessage(CLASS_NOT_FOUND);
-        message = PlatformString::Format(message, FClassName.data());
-        throw JavaException(FEnv, message);
-    }
-}
-
-JavaClass::~JavaClass() {
-    FEnv->DeleteLocalRef(FClass);
-}
-
-JavaStaticMethod JavaClass::GetStaticMethod(TString Name, TString Signature) {
-    jmethodID method = FEnv->GetStaticMethodID(FClass, PlatformString(Name),
-            PlatformString(Signature));
-
-    if (method == NULL || FEnv->ExceptionCheck() == JNI_TRUE) {
-        Messages& messages = Messages::GetInstance();
-        TString message = messages.GetMessage(METHOD_NOT_FOUND);
-        message = PlatformString::Format(message, Name.data(),
-                FClassName.data());
-        throw JavaException(FEnv, message);
-    }
-
-    return JavaStaticMethod(FEnv, FClass, method);
-}
-
-JavaClass::operator jclass () {
-    return FClass;
-}
-
-//----------------------------------------------------------------------------
-
-void JavaStringArray::Initialize(size_t Size) {
-    JavaClass jstringClass(FEnv, _T("java/lang/String"));
-
-    if (FEnv->ExceptionCheck() == JNI_TRUE) {
-        Messages& messages = Messages::GetInstance();
-        TString message = messages.GetMessage(CLASS_NOT_FOUND);
-        message = PlatformString::Format(message, _T("String"));
-        throw JavaException(FEnv, message.data());
-    }
-
-    jstring str = PlatformString("").toJString(FEnv);
-    FData = (jobjectArray)FEnv->NewObjectArray((jsize)Size, jstringClass, str);
-
-    if (FEnv->ExceptionCheck() == JNI_TRUE) {
-        throw JavaException(FEnv, _T("Error"));
-    }
-}
-
-JavaStringArray::JavaStringArray(JNIEnv *Env, size_t Size) {
-    FEnv = Env;
-    Initialize(Size);
-}
-
-JavaStringArray::JavaStringArray(JNIEnv *Env, jobjectArray Data) {
-    FEnv = Env;
-    FData = Data;
-}
-
-JavaStringArray::JavaStringArray(JNIEnv *Env, std::list<TString> Items) {
-    FEnv = Env;
-    Initialize(Items.size());
-    unsigned int index = 0;
-
-    for (std::list<TString>::const_iterator iterator = Items.begin();
-            iterator != Items.end(); iterator++) {
-        TString item = *iterator;
-        SetValue(index, PlatformString(item).toJString(FEnv));
-        index++;
-    }
-}
-
-jobjectArray JavaStringArray::GetData() {
-    return FData;
-}
-
-void JavaStringArray::SetValue(jsize Index, jstring Item) {
-    FEnv->SetObjectArrayElement(FData, Index, Item);
-
-    if (FEnv->ExceptionCheck() == JNI_TRUE) {
-        throw JavaException(FEnv, _T("Error"));
-    }
-}
-
-jstring JavaStringArray::GetValue(jsize Index) {
-    jstring result = (jstring)FEnv->GetObjectArrayElement(FData, Index);
-
-    if (FEnv->ExceptionCheck() == JNI_TRUE) {
-        throw JavaException(FEnv, _T("Error"));
-    }
-
-    return result;
-}
-
-unsigned int JavaStringArray::Count() {
-    unsigned int result = FEnv->GetArrayLength(FData);
-
-    if (FEnv->ExceptionCheck() == JNI_TRUE) {
-        throw JavaException(FEnv, _T("Error"));
-    }
-
-    return result;
-}
--- a/src/jdk.jpackage/share/native/library/common/JavaTypes.h	Fri Nov 23 09:12:00 2018 -0500
+++ b/src/jdk.jpackage/share/native/library/common/JavaTypes.h	Mon Dec 03 08:13:19 2018 -0500
@@ -31,13 +31,6 @@
 
 #include "jni.h"
 
-
-class JavaClass;
-class JavaStaticMethod;
-class JavaMethod;
-class JavaStringArray;
-
-
 class JavaException : public Exception {
 // Prohibit Heap-Based Classes.
 private:
@@ -61,93 +54,4 @@
     void Rethrow();
 };
 
-
-class JavaStaticMethod {
-// Prohibit Heap-Based Classes.
-private:
-    static void *operator new(size_t size);
-    static void operator delete(void *ptr);
-
-private:
-    JNIEnv *FEnv;
-    jmethodID FMethod;
-    jclass FClass;
-public:
-    JavaStaticMethod(JNIEnv *Env, jclass Class, jmethodID Method);
-
-    void CallVoidMethod(int Count, ...);
-    operator jmethodID ();
-};
-
-
-class JavaMethod {
-// Prohibit Heap-Based Classes.
-private:
-    static void *operator new(size_t size);
-    static void operator delete(void *ptr);
-
-    JavaMethod(JavaMethod const&); // Don't Implement.
-    void operator=(JavaMethod const&); // Don't implement
-
-private:
-    JNIEnv *FEnv;
-    jmethodID FMethod;
-    jobject FObj;
-public:
-    JavaMethod(JNIEnv *Env, jobject Obj, jmethodID Method);
-
-    void CallVoidMethod(int Count, ...);
-    operator jmethodID ();
-};
-
-
-class JavaClass {
-// Prohibit Heap-Based Classes.
-private:
-    static void *operator new(size_t size);
-    static void operator delete(void *ptr);
-
-    JavaClass(JavaClass const&); // Don't Implement.
-    void operator=(JavaClass const&); // Don't implement
-
-private:
-    JNIEnv *FEnv;
-    jclass FClass;
-    TString FClassName;
-
-public:
-    JavaClass(JNIEnv *Env, TString Name);
-    ~JavaClass();
-
-    JavaStaticMethod GetStaticMethod(TString Name, TString Signature);
-    operator jclass ();
-};
-
-
-class JavaStringArray {
-// Prohibit Heap-Based Classes.
-private:
-    static void *operator new(size_t size);
-    static void operator delete(void *ptr);
-
-    JavaStringArray(JavaStringArray const&); // Don't Implement.
-    void operator=(JavaStringArray const&); // Don't implement
-
-private:
-    JNIEnv *FEnv;
-    jobjectArray FData;
-
-    void Initialize(size_t Size);
-
-public:
-    JavaStringArray(JNIEnv *Env, size_t Size);
-    JavaStringArray(JNIEnv *Env, jobjectArray Data);
-    JavaStringArray(JNIEnv *Env, std::list<TString> Array);
-
-    jobjectArray GetData();
-    void SetValue(jsize Index, jstring Item);
-    jstring GetValue(jsize Index);
-    unsigned int Count();
-};
-
 #endif // JAVATYPES_H
--- a/src/jdk.jpackage/share/native/library/common/OrderedMap.h	Fri Nov 23 09:12:00 2018 -0500
+++ b/src/jdk.jpackage/share/native/library/common/OrderedMap.h	Mon Dec 03 08:13:19 2018 -0500
@@ -27,7 +27,7 @@
 #define ORDEREDMAP_H
 
 #ifdef WINDOWS
-#pragma warning(disable:4522) 
+#pragma warning(disable:4522)
 #endif
 
 #include <map>
--- a/src/jdk.jpackage/share/native/library/common/PosixPlatform.cpp	Fri Nov 23 09:12:00 2018 -0500
+++ b/src/jdk.jpackage/share/native/library/common/PosixPlatform.cpp	Mon Dec 03 08:13:19 2018 -0500
@@ -203,7 +203,7 @@
     bool result = false;
 
     if (FOutputHandle != 0 && IsRunning() == true) {
-        char buffer[4096];
+        char buffer[4096] = {0};
 
         ssize_t count = read(FOutputHandle, buffer, sizeof(buffer));
 
@@ -217,8 +217,8 @@
         } else if (count == 0) {
             // break;
         } else {
-            if (buffer[count] == EOF) {
-                buffer[count] = '\0';
+            if (buffer[count - 1] == EOF) {
+                buffer[count - 1] = '\0';
             }
 
             std::list<TString> output = Helpers::StringToArray(buffer);