Skip to content

Commit 0958263

Browse files
T-Svenssonjonahgraham
authored andcommitted
Bug 521515: Do not log every failed access attempt
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 <azoff@svenskalinuxforeningen.se>
1 parent a708a1d commit 0958263

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
org.eclipse.cdt.core.native/debug=false
2+
3+
# Used by org.eclipse.cdt.core.win32 fragment
4+
org.eclipse.cdt.core.native/debug/win32/registry=false

core/org.eclipse.cdt.core.native/build.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ bin.includes = plugin.properties,\
2020
about.mappings,\
2121
cdt_logo_icon32.png,\
2222
about.properties,\
23-
plugin.xml
23+
plugin.xml,\
24+
.options
2425
src.includes = about.html,\
2526
schema/,\
2627
native_src/

core/org.eclipse.cdt.core.win32/src/org/eclipse/cdt/internal/core/win32/WindowsRegistryImpl.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import org.eclipse.cdt.internal.core.natives.CNativePlugin;
1717
import org.eclipse.cdt.utils.WindowsRegistry;
18+
import org.eclipse.core.runtime.Platform;
1819

1920
import com.sun.jna.Native;
2021
import com.sun.jna.platform.win32.Advapi32;
@@ -33,6 +34,8 @@
3334
*/
3435
public class WindowsRegistryImpl extends WindowsRegistry {
3536

37+
private final static boolean DEBUG = Platform.getDebugBoolean(CNativePlugin.PLUGIN_ID + "/debug/win32/registry"); //$NON-NLS-1$
38+
3639
@Override
3740
public String getLocalMachineValue(String subkey, String name) {
3841
return getValue(WinReg.HKEY_LOCAL_MACHINE, subkey, name);
@@ -67,7 +70,9 @@ private String getValue(HKEY key, String subkey, String name) {
6770
try {
6871
return Advapi32Util.registryGetStringValue(key, subkey, name);
6972
} catch (Win32Exception e) {
70-
CNativePlugin.log(String.format("Unable to get value for %s in %s", name, subkey), e); //$NON-NLS-1$
73+
if (DEBUG) {
74+
CNativePlugin.log(String.format("Unable to get value for %s in %s", name, subkey), e); //$NON-NLS-1$
75+
}
7176
return null;
7277
}
7378
}
@@ -82,7 +87,9 @@ private String getKeyName(HKEY key, String subkey, int index) {
8287
Advapi32Util.registryCloseKey(phkKey.getValue());
8388
}
8489
} catch (Win32Exception e) {
85-
CNativePlugin.log(String.format("Unable to get keyname for %s at index %d", subkey, index), e); //$NON-NLS-1$
90+
if (DEBUG) {
91+
CNativePlugin.log(String.format("Unable to get keyname for %s at index %d", subkey, index), e); //$NON-NLS-1$
92+
}
8693
return null;
8794
}
8895
}
@@ -105,7 +112,9 @@ private String getValueName(HKEY key, String subkey, int index) {
105112
Advapi32Util.registryCloseKey(phkKey.getValue());
106113
}
107114
} catch (Win32Exception e) {
108-
CNativePlugin.log(String.format("Unable to get valuename for %s at index %d", subkey, index), e); //$NON-NLS-1$
115+
if (DEBUG) {
116+
CNativePlugin.log(String.format("Unable to get valuename for %s at index %d", subkey, index), e); //$NON-NLS-1$
117+
}
109118
return null;
110119
}
111120
}

0 commit comments

Comments
 (0)