EA-34998 Check qualified name from external before creating instance of FqName
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -54,11 +55,22 @@ public class FqName {
|
||||
|
||||
|
||||
private void validateFqName() {
|
||||
if (fqName.getFqName().indexOf('<') >= 0) {
|
||||
if (!isValidAfterUnsafeCheck(fqName.getFqName())) {
|
||||
throw new IllegalArgumentException("incorrect fq name: " + fqName);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidAfterUnsafeCheck(@NotNull String qualifiedName) {
|
||||
// TODO: There's a valid name with escape char ``
|
||||
return qualifiedName.indexOf('<') < 0;
|
||||
}
|
||||
|
||||
public static boolean isValid(@Nullable String qualifiedName) {
|
||||
return qualifiedName != null &&
|
||||
FqNameUnsafe.isValid(qualifiedName) &&
|
||||
isValidAfterUnsafeCheck(qualifiedName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFqName() {
|
||||
return fqName.getFqName();
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -59,11 +60,16 @@ public class FqNameUnsafe {
|
||||
|
||||
|
||||
private void validateFqName() {
|
||||
if (fqName.indexOf('/') >= 0 || fqName.indexOf('*') >= 0) {
|
||||
if (!isValid(fqName)) {
|
||||
throw new IllegalArgumentException("incorrect fq name: " + fqName);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isValid(@Nullable String qualifiedName) {
|
||||
// TODO: There's a valid name with escape char ``
|
||||
return qualifiedName != null && qualifiedName.indexOf('/') < 0 && qualifiedName.indexOf('*') < 0;
|
||||
}
|
||||
|
||||
private void compute() {
|
||||
int lastDot = fqName.lastIndexOf('.');
|
||||
if (lastDot >= 0) {
|
||||
|
||||
@@ -83,6 +83,10 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiClass[] findClasses(@NotNull String qualifiedNameString, @NotNull GlobalSearchScope scope) {
|
||||
if (!FqName.isValid(qualifiedNameString)) {
|
||||
return PsiClass.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
FqName qualifiedName = new FqName(qualifiedNameString);
|
||||
|
||||
// Backend searches for java.lang.String. Will fail with SOE if continue
|
||||
@@ -159,6 +163,10 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
|
||||
@Override
|
||||
public PsiPackage findPackage(@NotNull String qualifiedNameString) {
|
||||
if (!FqName.isValid(qualifiedNameString)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FqName fqName = new FqName(qualifiedNameString);
|
||||
|
||||
final List<JetFile> psiFiles = collectProjectJetFiles(project, GlobalSearchScope.allScope(project));
|
||||
|
||||
Reference in New Issue
Block a user