Incorrect String Comparison
Reported by
wangsong...@gmail.com,
Jan 31 2018
|
||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Platform: chrome://android
Steps to reproduce the problem:
Our tool DeepTect has detected several incorrect String comparison issues:
Path: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java
Code:
private static boolean isCachedPage(OfflinePageItem offlinePage) {
assert offlinePage != null;
String namespace = offlinePage.getClientId().getNamespace();
return namespace != OfflinePageBridge.DOWNLOAD_NAMESPACE
&& namespace != OfflinePageBridge.ASYNC_NAMESPACE
&& namespace != OfflinePageBridge.BROWSER_ACTIONS_NAMESPACE;
}
Path:
third_party/jmake/src/org/pantsbuild/jmake/CompatibilityChecker.java
Code:
String oMName, oMSig, nMName, nMSig;
...
if (oMName == nMNames[k] && oMSig == nMSignatures[k]) {
...
}
...
String newMName = nMNames[i];
final String newMSig = nMSignatures[i];
...
if (newMName == oMNames[j] && newMSig == oMSignatures[j]) {
...
}
Using "==" or "!=" to compare two Strings is not a good practice and may introduce unintended bugs. To fix these issues, developers should use the function "equals()" to compare two Strings.
What is the expected behavior?
What went wrong?
Using "==" or "!=" to compare two Strings is not a good practice and may introduce unintended bugs. To fix these issues, developers should use the function "equals()" to compare two Strings.
Did this work before? N/A
Chrome version: 63.0.3239.132 Channel: n/a
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version:
,
Jun 20 2018
|
||
►
Sign in to add a comment |
||
Comment 1 by abodenha@chromium.org
, Feb 2 2018