Fix NPE on empty JVM name

#KT-9113 Fixed
This commit is contained in:
Alexander Udalov
2015-09-09 15:09:03 +03:00
parent fb31980c0b
commit 3e5c8d1b79
7 changed files with 24 additions and 11 deletions
@@ -53,7 +53,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
MAP.put(ErrorsJvm.OVERLOADS_ABSTRACT, "''JvmOverloads'' annotation cannot be used on abstract methods");
MAP.put(ErrorsJvm.OVERLOADS_PRIVATE, "''JvmOverloads'' annotation has no effect on private and local declarations");
MAP.put(ErrorsJvm.INAPPLICABLE_JVM_NAME, "''JvmName'' annotation is not applicable to this declaration");
MAP.put(ErrorsJvm.ILLEGAL_JVM_NAME, "Illegal JVM name: ''{0}''", STRING);
MAP.put(ErrorsJvm.ILLEGAL_JVM_NAME, "Illegal JVM name");
MAP.put(ErrorsJvm.EXTERNAL_DECLARATION_CANNOT_BE_ABSTRACT, "External declaration can not be abstract");
MAP.put(ErrorsJvm.EXTERNAL_DECLARATION_CANNOT_HAVE_BODY, "External declaration can not have a body");
MAP.put(ErrorsJvm.EXTERNAL_DECLARATION_IN_TRAIT, "Members of interfaces can not be external");
@@ -44,7 +44,7 @@ public interface ErrorsJvm {
DiagnosticFactory0<JetDeclaration> JVM_STATIC_NOT_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
DiagnosticFactory0<PsiElement> INAPPLICABLE_JVM_NAME = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<JetAnnotationEntry, String> ILLEGAL_JVM_NAME = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<JetAnnotationEntry> ILLEGAL_JVM_NAME = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetDeclaration> OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
DiagnosticFactory0<JetDeclaration> OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.jvm.RuntimeAssertionsTypeChecker
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.load.java.lazy.types.RawTypeTag
import org.jetbrains.kotlin.load.java.lazy.types.isMarkedNotNull
import org.jetbrains.kotlin.load.java.lazy.types.isMarkedNullable
import org.jetbrains.kotlin.load.kotlin.JavaAnnotationCallChecker
@@ -200,7 +199,7 @@ public class JvmNameAnnotationChecker : DeclarationChecker {
val value = DescriptorUtils.getJvmName(descriptor)
if (value == null || !Name.isValidIdentifier(value)) {
diagnosticHolder.report(ErrorsJvm.ILLEGAL_JVM_NAME.on(annotationEntry, value))
diagnosticHolder.report(ErrorsJvm.ILLEGAL_JVM_NAME.on(annotationEntry))
}
if (descriptor is CallableMemberDescriptor) {
@@ -0,0 +1,8 @@
<!ILLEGAL_JVM_NAME!>@JvmName(<!NO_VALUE_FOR_PARAMETER!>)<!><!>
fun foo() {}
<!ILLEGAL_JVM_NAME!>@JvmName(<!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!>)<!>
fun bar() {}
@JvmName("a", <!TOO_MANY_ARGUMENTS!>"b"<!>)
fun baz() {}
@@ -0,0 +1,5 @@
package
kotlin.jvm.JvmName(name = 42) public fun bar(): kotlin.Unit
kotlin.jvm.JvmName(name = "a") public fun baz(): kotlin.Unit
kotlin.jvm.JvmName() public fun foo(): kotlin.Unit
@@ -763,6 +763,12 @@ public class JetDiagnosticsTestWithStdLibGenerated extends AbstractJetDiagnostic
doTest(fileName);
}
@TestMetadata("ea70880_illegalJvmName.kt")
public void testEa70880_illegalJvmName() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/regression/ea70880_illegalJvmName.kt");
doTest(fileName);
}
@TestMetadata("kt2082.kt")
public void testKt2082() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/regression/kt2082.kt");
@@ -562,8 +562,8 @@ public class DescriptorUtils {
}
@Nullable
public static String getJvmName(@NotNull Annotations annotations) {
AnnotationDescriptor jvmNameAnnotation = getJvmNameAnnotation(annotations);
public static String getJvmName(@NotNull Annotated annotated) {
AnnotationDescriptor jvmNameAnnotation = getJvmNameAnnotation(annotated.getAnnotations());
if (jvmNameAnnotation == null) return null;
Map<ValueParameterDescriptor, ConstantValue<?>> arguments = jvmNameAnnotation.getAllValueArguments();
@@ -575,11 +575,6 @@ public class DescriptorUtils {
return ((StringValue) name).getValue();
}
@Nullable
public static String getJvmName(@NotNull Annotated annotated) {
return getJvmName(annotated.getAnnotations());
}
@Nullable
public static AnnotationDescriptor getJvmNameAnnotation(@NotNull Annotations annotations) {
AnnotationDescriptor jvmNameAnnotation = annotations.findAnnotation(JVM_NAME);