From 2e0869c0e8cf5f4125a3237f22ed6f166a065fbb Mon Sep 17 00:00:00 2001 From: Arun Thondapu Date: Tue, 25 Apr 2017 16:33:14 +0530 Subject: Bug 493761: Platform won't launch on Java 9-ea builds (InjectionException: NoClassDefFoundError: javax/annotation/PostConstruct) --add-modules VM argument is needed to run eclipse with Java 9 but Java 8 does not recognize this argument and fails to start up. This patch prevents passing the --add-modules argument to the JVM if it is present in the VM argument list and the JVM version is < 9. Tested with different builds of Java 8 and Java 9 on Linux, Mac and Windows. Also tested with both formats of specifying the argument (one-arg with "=", or two-arg). Change-Id: I0d4c6ba2ba0e41982a89d7da1aef6c78f276f65c Signed-off-by: Arun Thondapu --- .../library/cocoa/eclipseCocoa.c | 40 ++++++++++------------ 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c') diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c index 6bfa9def6..023223103 100644 --- a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c +++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCocoa.c @@ -44,7 +44,7 @@ char *findCommand(char *command); char* defaultVM = "java"; char* vmLibrary = "JavaVM"; char* shippedVMDir = "../../jre/Contents/Home/bin/"; // relative to launcher -int isSunMaxPermSizeVM = 0; +int isModularJVM = 0; static void adjustLibraryPath(char * vmLibrary); static char * findLib(char * command); @@ -330,7 +330,8 @@ char** getArgVM( char* vm ) return result; } -char * getJavaVersion(char* command) { +/* set isModularJVM to 1 if the JVM version is >= 9, 0 otherwise */ +void checkJavaVersion(char* command) { FILE *fp; char buffer[4096]; char *version = NULL, *firstChar; @@ -338,7 +339,7 @@ char * getJavaVersion(char* command) { sprintf(buffer,"%s -version 2>&1", command); fp = popen(buffer, "r"); if (fp == NULL) { - return NULL; + return; } while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) { if (!version) { @@ -354,25 +355,20 @@ char * getJavaVersion(char* command) { version[numChars] = '\0'; } } - if (strstr(buffer, "Java HotSpot(TM)") || strstr(buffer, "OpenJDK")) { - if (version != NULL) { - _TCHAR *value = strtok(version, "."); - if (value != NULL && (strtol(value, NULL, 10) == 1)) { - value = strtok(NULL, "."); - if (strtol(value, NULL, 10) < 8) { - isSunMaxPermSizeVM = 1; - } - } + if (version != NULL) { + char *str = version; + /* According to the new Java version-string scheme, the first element is + * the major version number, details at http://openjdk.java.net/jeps/223 */ + char *majorVersion = strtok(str, ".-"); + if (majorVersion != NULL && (strtol(majorVersion, NULL, 10) >= 9)) { + isModularJVM = 1; } - break; - } - if (strstr(buffer, "IBM") != NULL) { - isSunMaxPermSizeVM = 0; - break; + free(version); } + break; } pclose(fp); - return version; + return; } char * getJavaHome() { @@ -429,8 +425,8 @@ char * findVMLibrary( char* command ) { if (strstr(cmd, "/JavaVM.framework/") != NULL && (strstr(cmd, "/Current/") != NULL || strstr(cmd, "/A/") != NULL)) { cmd = getJavaHome(); } - // This is necessary to initialize isSunMaxPermSizeVM - getJavaVersion(cmd); + // This is necessary to initialize isModularJVM + checkJavaVersion(cmd); result = JAVA_FRAMEWORK; if (strstr(cmd, "/JavaVM.framework/") == NULL) { char * lib = findLib(cmd); @@ -625,8 +621,8 @@ void processVMArgs(char **vmargs[] ) } } -int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) { - return isSunMaxPermSizeVM; +int isModularVM( _TCHAR * javaVM, _TCHAR * jniLib ) { + return isModularJVM; } NSString* getApplicationSupport() { -- cgit v1.2.1