From 89dd1a248f586d1b372c1f04b66417eea91614dc Mon Sep 17 00:00:00 2001 From: Carsten Hammer Date: Sun, 6 Dec 2020 19:02:02 +0100 Subject: Bug 572584 - Potentially dangerous use of non-short-circuit logic in org.eclipse.debug.internal.core.DebugOptions.optionsChanged(DebugOptions) org.eclipse.debug.internal.core.LaunchManager$ResourceProxyVisitor.visit(IResourceProxy) .. This code seems to be using non-short-circuit logic (e.g., & or |) rather than short-circuit logic (&& or ||). In addition, it seem possible that, depending on the value of the left hand side, you might not want to evaluate the right hand side (because it would have side effects, could cause an exception or could be expensive. Non-short-circuit logic causes both sides of the expression to be evaluated even when the result can be inferred from knowing the left-hand side. This can be less efficient and can result in errors if the left-hand side guards cases when evaluating the right-hand side can generate an error. See the Java Language Specification for details. Rank: Of Concern (15), confidence: High Pattern: NS_DANGEROUS_NON_SHORT_CIRCUIT Type: NS, Category: STYLE (Dodgy code) Change-Id: Ib234c4f879ec39de41c661d4532ba2afdfaa1d69 Signed-off-by: Carsten Hammer --- .../core/org/eclipse/debug/internal/core/DebugOptions.java | 4 ++-- .../core/org/eclipse/debug/internal/core/LaunchManager.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugOptions.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugOptions.java index 841b06ae6..e03eec7e3 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugOptions.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/DebugOptions.java @@ -56,8 +56,8 @@ public class DebugOptions implements DebugOptionsListener { public void optionsChanged(org.eclipse.osgi.service.debug.DebugOptions options) { fgDebugTrace = options.newDebugTrace(DebugPlugin.getUniqueIdentifier()); DEBUG = options.getBooleanOption(DEBUG_FLAG, false); - DEBUG_COMMANDS = DEBUG & options.getBooleanOption(DEBUG_FLAG_COMMANDS, false); - DEBUG_EVENTS = DEBUG & options.getBooleanOption(DEBUG_FLAG_EVENTS, false); + DEBUG_COMMANDS = DEBUG && options.getBooleanOption(DEBUG_FLAG_COMMANDS, false); + DEBUG_EVENTS = DEBUG && options.getBooleanOption(DEBUG_FLAG_EVENTS, false); } /** diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java index 477ce0dce..fb9c0c749 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchManager.java @@ -453,7 +453,7 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe @Override public boolean visit(IResourceProxy proxy) { if (proxy.getType() == IResource.FILE) { - if (ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION.equalsIgnoreCase(proxy.requestFullPath().getFileExtension()) | ILaunchConfiguration.LAUNCH_CONFIGURATION_PROTOTYPE_FILE_EXTENSION.equalsIgnoreCase(proxy.requestFullPath().getFileExtension())) { + if (ILaunchConfiguration.LAUNCH_CONFIGURATION_FILE_EXTENSION.equalsIgnoreCase(proxy.requestFullPath().getFileExtension()) || ILaunchConfiguration.LAUNCH_CONFIGURATION_PROTOTYPE_FILE_EXTENSION.equalsIgnoreCase(proxy.requestFullPath().getFileExtension())) { fList.add(proxy.requestResource()); } return false; @@ -1662,7 +1662,7 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe // compatibility. initializePreferredDelegates(); for (PreferredDelegate pd : fPreferredDelegates) { - if(pd.getModes().equals(modes) & pd.getTypeId().equals(typeid)) { + if (pd.getModes().equals(modes) && pd.getTypeId().equals(typeid)) { return pd.getDelegate(); } } @@ -2393,7 +2393,7 @@ public class LaunchManager extends PlatformObject implements ILaunchManager, IRe try { for (ILaunch launch : launches) { for (ILaunchConfiguration config : configs) { - if(config.equals(launch.getLaunchConfiguration()) & launch.canTerminate()) { + if (config.equals(launch.getLaunchConfiguration()) && launch.canTerminate()) { launch.terminate(); } } -- cgit v1.2.3