From 18519d4159352a23b745eff5dea1b6e2a480c0f3 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 17 Oct 2017 16:44:26 +0200 Subject: [PATCH] [platform] JnaLoader.isLoaded() should shield callers from exceptions (IDEA-CR-25658) --- .../src/com/intellij/idea/StartupUtil.java | 24 ++----------------- .../util/src/com/intellij/jna/JnaLoader.java | 16 +++++++++---- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java index b13b5082a747..6babf40100d8 100644 --- a/platform/platform-impl/src/com/intellij/idea/StartupUtil.java +++ b/platform/platform-impl/src/com/intellij/idea/StartupUtil.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.idea; import com.intellij.ide.cloudConfig.CloudConfigProvider; @@ -38,7 +24,6 @@ import com.intellij.ui.AppUIUtil; import com.intellij.util.Consumer; import com.intellij.util.EnvironmentUtil; import com.intellij.util.PlatformUtils; -import com.intellij.util.lang.UrlClassLoader; import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Level; import org.apache.log4j.PatternLayout; @@ -335,12 +320,7 @@ public class StartupUtil { if (System.getProperty("jna.nosys") == null) { System.setProperty("jna.nosys", "true"); // prefer bundled JNA dispatcher lib } - try { - JnaLoader.load(log); - } - catch (Throwable t) { - log.error("Unable to load JNA library (OS: " + SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION + ")", t); - } + JnaLoader.load(log); if (SystemInfo.isWin2kOrNewer) { IdeaWin32.isAvailable(); // logging is done there diff --git a/platform/util/src/com/intellij/jna/JnaLoader.java b/platform/util/src/com/intellij/jna/JnaLoader.java index ad6f2a134daa..628b03077dac 100644 --- a/platform/util/src/com/intellij/jna/JnaLoader.java +++ b/platform/util/src/com/intellij/jna/JnaLoader.java @@ -14,6 +14,7 @@ package com.intellij.jna; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.SystemInfo; import com.sun.jna.Native; public class JnaLoader { @@ -22,11 +23,16 @@ public class JnaLoader { public static synchronized void load(Logger logger) { if (ourJnaLoaded == null) { ourJnaLoaded = Boolean.FALSE; - long t = System.currentTimeMillis(); - int ptrSize = Native.POINTER_SIZE; - t = System.currentTimeMillis() - t; - logger.info("JNA library (" + (ptrSize << 3) + "-bit) loaded in " + t + " ms"); - ourJnaLoaded = Boolean.TRUE; + try { + long t = System.currentTimeMillis(); + int ptrSize = Native.POINTER_SIZE; + t = System.currentTimeMillis() - t; + logger.info("JNA library (" + (ptrSize << 3) + "-bit) loaded in " + t + " ms"); + ourJnaLoaded = Boolean.TRUE; + } + catch (Throwable t) { + logger.error("Unable to load JNA library (OS: " + SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION + ")", t); + } } }