The !. operator will not work on java.lang.System?


#1

Hi, is this compile error intended? So is this mean "!!." will only work for instance variable only?

fun main(args: Array<String>) {   val p = System!!.getProperties()   println(p) }

output>
EXCEPTION: java.lang.UnsupportedOperationException: Only member lookup is allowed on a namespace type System
  at org.jetbrains.jet.lang.types.NamespaceType.throwException(NamespaceType.java:55)
  at org.jetbrains.jet.lang.types.NamespaceType.isNullable(NamespaceType.java:67)
  at org.jetbrains.jet.lang.types.TypeUtils.makeNullableAsSpecified(TypeUtils.java:91)
  at org.jetbrains.jet.lang.types.TypeUtils.makeNotNullable(TypeUtils.java:86)
  at org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure.isSubtypeOf(TypeCheckingProcedure.java:165)
  at org.jetbrains.jet.lang.types.checker.JetTypeChecker.isSubtypeOf(JetTypeChecker.java:38)
  at org.jetbrains.jet.lang.types.TypeUtils.equalTypes(TypeUtils.java:457)
  at org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory.createDataFlowValue(DataFlowValueFactory.java:47)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.isKnownToBeNotNull(BasicExpressionTypingVisitor.java:1025)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitExclExclExpression(BasicExpressionTypingVisitor.java:996)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitUnaryExpression(BasicExpressionTypingVisitor.java:909)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitUnaryExpression(BasicExpressionTypingVisitor.java:892)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitUnaryExpression(BasicExpressionTypingVisitor.java:65)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitPostfixExpression(JetVisitor.java:177)
  at org.jetbrains.jet.lang.psi.JetPostfixExpression.accept(JetPostfixExpression.java:44)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.visitJetElement(ExpressionTypingVisitorDispatcher.java:230)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.visitJetElement(ExpressionTypingVisitorDispatcher.java:37)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitExpression(JetVisitor.java:148)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitUnaryExpression(JetVisitor.java:181)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitPostfixExpression(JetVisitor.java:177)
  at org.jetbrains.jet.lang.psi.JetPostfixExpression.accept(JetPostfixExpression.java:44)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:125)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:93)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitQualifiedExpression(BasicExpressionTypingVisitor.java:651)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitQualifiedExpression(BasicExpressionTypingVisitor.java:65)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitDotQualifiedExpression(JetVisitor.java:261)
  at org.jetbrains.jet.lang.psi.JetDotQualifiedExpression.accept(JetDotQualifiedExpression.java:37)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.visitJetElement(ExpressionTypingVisitorDispatcher.java:230)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.visitJetElement(ExpressionTypingVisitorDispatcher.java:37)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitExpression(JetVisitor.java:148)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitQualifiedExpression(JetVisitor.java:253)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitDotQualifiedExpression(JetVisitor.java:261)
  at org.jetbrains.jet.lang.psi.JetDotQualifiedExpression.accept(JetDotQualifiedExpression.java:37)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:125)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:93)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices.getTypeInfo(ExpressionTypingServices.java:125)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices.getType(ExpressionTypingServices.java:130)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices.safeGetType(ExpressionTypingServices.java:113)
  at org.jetbrains.jet.lang.resolve.DescriptorResolver$2.compute(DescriptorResolver.java:994)
  at org.jetbrains.jet.lang.resolve.DescriptorResolver$2.compute(DescriptorResolver.java:991)
  at org.jetbrains.jet.util.lazy.LazyValue.get(LazyValue.java:48)
  at org.jetbrains.jet.lang.resolve.DescriptorResolver.getVariableType(DescriptorResolver.java:1001)
  at org.jetbrains.jet.lang.resolve.DescriptorResolver.resolveLocalVariableDescriptor(DescriptorResolver.java:754)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorForStatements.visitProperty(ExpressionTypingVisitorForStatements.java:110)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorForStatements.visitProperty(ExpressionTypingVisitorForStatements.java:50)
  at org.jetbrains.jet.lang.psi.JetProperty.accept(JetProperty.java:60)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:125)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:100)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices.getBlockReturnedTypeWithWritableScope(ExpressionTypingServices.java:344)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices.getBlockReturnedType(ExpressionTypingServices.java:206)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitBlockExpression(BasicExpressionTypingVisitor.java:634)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitBlockExpression(BasicExpressionTypingVisitor.java:630)
  at org.jetbrains.jet.lang.types.expressions.BasicExpressionTypingVisitor.visitBlockExpression(BasicExpressionTypingVisitor.java:65)
  at org.jetbrains.jet.lang.psi.JetBlockExpression.accept(JetBlockExpression.java:50)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.visitJetElement(ExpressionTypingVisitorDispatcher.java:230)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.visitJetElement(ExpressionTypingVisitorDispatcher.java:37)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitExpression(JetVisitor.java:148)
  at org.jetbrains.jet.lang.psi.JetVisitor.visitBlockExpression(JetVisitor.java:277)
  at org.jetbrains.jet.lang.psi.JetBlockExpression.accept(JetBlockExpression.java:50)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:125)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:93)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingVisitorDispatcher.getTypeInfo(ExpressionTypingVisitorDispatcher.java:98)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices.checkFunctionReturnType(ExpressionTypingServices.java:181)
  at org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices.checkFunctionReturnType(ExpressionTypingServices.java:159)
  at org.jetbrains.jet.lang.resolve.BodyResolver.resolveFunctionBody(BodyResolver.java:513)
  at org.jetbrains.jet.lang.resolve.BodyResolver.resolveFunctionBodies(BodyResolver.java:497)
  at org.jetbrains.jet.lang.resolve.BodyResolver.resolveBehaviorDeclarationBodies(BodyResolver.java:131)
  at org.jetbrains.jet.lang.resolve.BodyResolver.resolveBodies(BodyResolver.java:141)
  at org.jetbrains.jet.lang.resolve.TopDownAnalyzer.doProcess(TopDownAnalyzer.java:134)
  at org.jetbrains.jet.lang.resolve.TopDownAnalyzer.analyzeFiles(TopDownAnalyzer.java:259)
  at org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(AnalyzerFacadeForJVM.java:204)
  at org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(AnalyzerFacadeForJVM.java:186)
  at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$1.invoke(KotlinToJVMBytecodeCompiler.java:317)
  at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$1.invoke(KotlinToJVMBytecodeCompiler.java:313)
  at org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.java:212)
  at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.java:312)
  at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.java:292)
  at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyzeAndGenerate(KotlinToJVMBytecodeCompiler.java:273)
  at org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileBunchOfSources(KotlinToJVMBytecodeCompiler.java:187)
  at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:141)
  at org.jetbrains.jet.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.java:53)
  at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:117)
  at org.jetbrains.jet.cli.jvm.K2JVMCompiler.exec(K2JVMCompiler.java:179)
  at org.jetbrains.jet.cli.jvm.K2JVMCompiler.exec(K2JVMCompiler.java:53)
  at org.jetbrains.jet.cli.common.CLICompiler.exec(CLICompiler.java:47)
  at org.jetbrains.jet.cli.common.CLICompiler.doMainNoExit(CLICompiler.java:160)
  at org.jetbrains.jet.cli.common.CLICompiler.doMain(CLICompiler.java:151)
  at org.jetbrains.jet.cli.jvm.K2JVMCompiler.main(K2JVMCompiler.java:57)

exec() finished with INTERNAL_ERROR return code


#2

I guess that you want to say this instead:

``

val p = System.getProperties()!!

#3

Ahh, yes. Thank you Juha for pointing that out. I get confused on the usage of !! operator.


#4

I think you should create a bug report for this. It should be a compiler error, not a run-time error.

youtrack.jetbrains.com


#5

Flow, the error is thrown at compile time!

Perhaps I would suggest a more shorter and more user friendly error message improvement would be nice :slight_smile:


#6

It's a bug, please report it to the tracker. Thanks.


#7

Sure Andrey. Here http://youtrack.jetbrains.com/issue/KT-3100