Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2017-10-28 09:34:14 +0000
committerAndrey Loskutov2017-11-22 08:09:12 +0000
commit49307556c401e403b16280c49eb69fbdfff6300b (patch)
treee4401f951454f2d78bebc3ef2122abd43efa927e
parent2c4e46a161c87faff7d830d04cd9ce262b2a9e54 (diff)
downloadeclipse.jdt.core-49307556c401e403b16280c49eb69fbdfff6300b.tar.gz
eclipse.jdt.core-49307556c401e403b16280c49eb69fbdfff6300b.tar.xz
eclipse.jdt.core-49307556c401e403b16280c49eb69fbdfff6300b.zip
Bug 526591 - fix "using .equals to compare two char[]'s"
Calling equals() on an array is the same as comparing their addresses, but it does not compare the array contents and could lead to NPE's if array reference was null. Sometimes the intent was really to compare the contents, so the code never worked in the expected way. Avoid confusing or wrong code and potential NPE's by explicitly check pointer equality using == or by using Arrays.equals() to compare the array contents. Change-Id: I08f774657ac1be54ad4895764d4f7168b440b630 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java2
-rw-r--r--org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java4
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java8
-rw-r--r--org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java10
4 files changed, 12 insertions, 12 deletions
diff --git a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java
index 7335a6bf3a..e399d7db11 100644
--- a/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java
+++ b/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java
@@ -160,7 +160,7 @@ private NameEnvironmentAnswer findClassInternal(char[] typeName, String qualifie
}
public NameEnvironmentAnswer findSecondaryInClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
//"package-info" is a reserved class name and can never be a secondary type (it is much faster to stop the search here).
- if(TypeConstants.PACKAGE_INFO_NAME.equals(typeName)) {
+ if(CharOperation.equals(TypeConstants.PACKAGE_INFO_NAME, typeName)) {
return null;
}
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index 886f7318b8..d658c10538 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -2376,7 +2376,7 @@ public final class CompletionEngine
contextAccepted = true;
processModuleKeywordCompletion(parsedUnit, target, (CompletionOnKeyword) target);
} else {
- if (target.moduleName != null || target.moduleName.equals(CharOperation.NO_CHAR))
+ if (target.moduleName != null || target.moduleName == CharOperation.NO_CHAR)
skipSet.add(new String(target.moduleName));
}
}
@@ -11974,7 +11974,7 @@ public final class CompletionEngine
TypeReference[] prevImpls = prevProvides.implementations;
for (TypeReference prevImpl : prevImpls) {
char[][] typeName = prevImpl.getTypeName();
- if (typeName.equals(CharOperation.NO_CHAR_CHAR)) continue;
+ if (typeName == CharOperation.NO_CHAR_CHAR) continue;
existingImpl.add(CharOperation.toString(typeName));
}
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java
index de3f4ceca0..0d264dec5b 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/BinaryIndexer.java
@@ -871,23 +871,23 @@ public class BinaryIndexer extends AbstractIndexer implements SuffixConstants {
for (IPackageExport pack : exportedPackages) {
addModuleExportedPackages(pack.name());
char[][] tgts = pack.targets();
- if (tgts == null || tgts.equals(CharOperation.NO_CHAR_CHAR)) continue;
+ if (tgts == null || tgts == CharOperation.NO_CHAR_CHAR) continue;
for (char[] tgt : tgts) {
- if (tgt != null && !tgt.equals(CharOperation.NO_CHAR))
+ if (tgt != null && tgt != CharOperation.NO_CHAR)
addModuleReference(tgt);
}
}
}
}
private void indexTypeReferences(char[][] ref) {
- if (ref == null || ref.equals(CharOperation.NO_CHAR))
+ if (ref == null || ref == CharOperation.NO_CHAR_CHAR)
return;
for (int i = 0; i < ref.length; i++) {
addTypeReference(ref[i]);
}
}
private void indexTypeReference(char[] ref) {
- if (ref == null || ref.equals(CharOperation.NO_CHAR))
+ if (ref == null || ref == CharOperation.NO_CHAR)
return;
addTypeReference(ref);
}
diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java
index 84c63312c6..cb45a5e160 100644
--- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java
+++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/SourceIndexerRequestor.java
@@ -304,7 +304,7 @@ public void enterModule(ModuleInfo moduleInfo) {
this.indexer.addModuleDeclaration(moduleInfo.moduleName);
if (moduleInfo.requires != null) {
for (ISourceElementRequestor.RequiresInfo req : moduleInfo.requires) {
- if (req == null || req.moduleName == null || req.moduleName.equals(CharOperation.NO_CHAR)) continue;
+ if (req == null || req.moduleName == null || req.moduleName == CharOperation.NO_CHAR) continue;
this.indexer.addModuleReference(req.moduleName);
}
}
@@ -316,15 +316,15 @@ private void enterPackageVisibilityInfo(ISourceElementRequestor.PackageExportInf
if (packInfos == null)
return;
for (ISourceElementRequestor.PackageExportInfo packInfo : packInfos) {
- if (packInfo == null || packInfo.pkgName == null || packInfo.pkgName.equals(CharOperation.NO_CHAR)) continue;
+ if (packInfo == null || packInfo.pkgName == null || packInfo.pkgName == CharOperation.NO_CHAR) continue;
this.indexer.addModuleExportedPackages(packInfo.pkgName);
char[][] tgts = packInfo.targets;
- if (tgts == null || tgts.equals(CharOperation.NO_CHAR_CHAR)) continue;
+ if (tgts == null || tgts == CharOperation.NO_CHAR_CHAR) continue;
for (char[] tgt : tgts) {
- if (tgt != null && !tgt.equals(CharOperation.NO_CHAR))
+ if (tgt != null && tgt != CharOperation.NO_CHAR)
this.indexer.addModuleReference(tgt);
}
- }
+}
}
/**
* @see ISourceElementRequestor#enterMethod(ISourceElementRequestor.MethodInfo)

Back to the top