From 09582630d7357e8069098883d589cd9bfb18beed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Svensson?= Date: Tue, 18 Aug 2020 20:04:30 +0200 Subject: [PATCH] Bug 521515: Do not log every failed access attempt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Windows registry can be checked for keys that may not exist. In order to avoid logging an exception that the entry is missing when it's not critical that the entry do exist, the method should just return null and let the caller handle if it's critical or not that the entry exists. To easily debug situations where the entry is supposed to always exist, the trace symbol "org.eclipse.cdt.core.native/debug/win32/registry" can be set to "true" and the exceptions will be logged in any case. Change-Id: I6603cbe363ebecd357fa44c41fb1a26c6345dd70 Signed-off-by: Torbjörn Svensson --- core/org.eclipse.cdt.core.native/.options | 4 ++++ core/org.eclipse.cdt.core.native/build.properties | 3 ++- .../internal/core/win32/WindowsRegistryImpl.java | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 core/org.eclipse.cdt.core.native/.options diff --git a/core/org.eclipse.cdt.core.native/.options b/core/org.eclipse.cdt.core.native/.options new file mode 100644 index 00000000000..77eda67bb6f --- /dev/null +++ b/core/org.eclipse.cdt.core.native/.options @@ -0,0 +1,4 @@ +org.eclipse.cdt.core.native/debug=false + +# Used by org.eclipse.cdt.core.win32 fragment +org.eclipse.cdt.core.native/debug/win32/registry=false \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.native/build.properties b/core/org.eclipse.cdt.core.native/build.properties index 006a08c7bcb..641b4f3e264 100644 --- a/core/org.eclipse.cdt.core.native/build.properties +++ b/core/org.eclipse.cdt.core.native/build.properties @@ -20,7 +20,8 @@ bin.includes = plugin.properties,\ about.mappings,\ cdt_logo_icon32.png,\ about.properties,\ - plugin.xml + plugin.xml,\ + .options src.includes = about.html,\ schema/,\ native_src/ diff --git a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java index dcb48a8fc7b..0327dbffcf9 100644 --- a/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java +++ b/core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java @@ -15,6 +15,7 @@ package org.eclipse.cdt.internal.core.win32; import org.eclipse.cdt.internal.core.natives.CNativePlugin; import org.eclipse.cdt.utils.WindowsRegistry; +import org.eclipse.core.runtime.Platform; import com.sun.jna.Native; import com.sun.jna.platform.win32.Advapi32; @@ -33,6 +34,8 @@ import com.sun.jna.ptr.IntByReference; */ public class WindowsRegistryImpl extends WindowsRegistry { + private final static boolean DEBUG = Platform.getDebugBoolean(CNativePlugin.PLUGIN_ID + "/debug/win32/registry"); //$NON-NLS-1$ + @Override public String getLocalMachineValue(String subkey, String name) { return getValue(WinReg.HKEY_LOCAL_MACHINE, subkey, name); @@ -67,7 +70,9 @@ public class WindowsRegistryImpl extends WindowsRegistry { try { return Advapi32Util.registryGetStringValue(key, subkey, name); } catch (Win32Exception e) { - CNativePlugin.log(String.format("Unable to get value for %s in %s", name, subkey), e); //$NON-NLS-1$ + if (DEBUG) { + CNativePlugin.log(String.format("Unable to get value for %s in %s", name, subkey), e); //$NON-NLS-1$ + } return null; } } @@ -82,7 +87,9 @@ public class WindowsRegistryImpl extends WindowsRegistry { Advapi32Util.registryCloseKey(phkKey.getValue()); } } catch (Win32Exception e) { - CNativePlugin.log(String.format("Unable to get keyname for %s at index %d", subkey, index), e); //$NON-NLS-1$ + if (DEBUG) { + CNativePlugin.log(String.format("Unable to get keyname for %s at index %d", subkey, index), e); //$NON-NLS-1$ + } return null; } } @@ -105,7 +112,9 @@ public class WindowsRegistryImpl extends WindowsRegistry { Advapi32Util.registryCloseKey(phkKey.getValue()); } } catch (Win32Exception e) { - CNativePlugin.log(String.format("Unable to get valuename for %s at index %d", subkey, index), e); //$NON-NLS-1$ + if (DEBUG) { + CNativePlugin.log(String.format("Unable to get valuename for %s at index %d", subkey, index), e); //$NON-NLS-1$ + } return null; } }