Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

IntelliJ flags green instruction as red with Copy task filter method #1065

Open
jnizet opened this issue Aug 24, 2018 · 3 comments
Open

IntelliJ flags green instruction as red with Copy task filter method #1065

jnizet opened this issue Aug 24, 2018 · 3 comments

Comments

@jnizet
Copy link
Contributor

jnizet commented Aug 24, 2018

Expected Behavior

I expect IntelliJ not to flag the code as incorrect

Current Behavior

The IntelliJ editor flags the code as incorrect (see below for details)

Context

I was translating the "working with files" example of the gradle user guide when I noticed this. No clear idea if it's a DSL or an IntelliJ bug, but Eric Wendelin asked me to submit an issue here, so here it goes.
Feel free to open an issue for IntelliJ if necessary.

Steps to Reproduce (for bugs)

  • Install Gradle 4.10-rc-3 (using the wrapper)
  • Create a gradle build script in Kotlin with the following task:
tasks.create<Copy>("bizarreIdeaBug") {
    from("a")
    into("b")
    filter { line: String ->
        if (line.startsWith("-")) null else line
    }
}

Open it in IntelliJ. Here's my version:
IntelliJ IDEA 2018.2.2 (Ultimate Edition)
Build #IU-182.4129.33, built on August 21, 2018
JRE: 1.8.0_152-release-1248-b8 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

executing the task works fine. Importing the project in IntelliJ works fine, but the editor complains, with a red squiggly line under null, with a message saying "Null can not be a value of a non-null type String"

Your Environment

------------------------------------------------------------
Gradle 4.10-rc-3
------------------------------------------------------------

Build time:   2018-08-23 12:07:56 UTC
Revision:     1b827f2119c11123e178e731421ae79d52a8991a

Kotlin DSL:   1.0-rc-3
Kotlin:       1.2.60
Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM:          1.8.0_152 (Oracle Corporation 25.152-b16)
OS:           Mac OS X 10.13.6 x86_64
@eskatos
Copy link
Member

eskatos commented Sep 18, 2018

I can confirm something is going on.

Using IntelliJ IDEA 2018.2.3 with the Kotlin plugin v1.2.70 I get:

image

Which is different from what you got with 2018.2.2 (and what version of the Kotlin plugin?). Other behavior is the same: compiles and runs fine from the command line.

Intellij can be made happy by casting lying:

image

But it doesn't make sense.

It is as if IntelliJ interprets CopySpec filter(Transformer<String, String> transformer); with JSR-305 strict mode differently than the Kotlin compiler.

Given the return type is a type parameter it should be String!, allowing null.

@JLLeitschuh
Copy link
Contributor

JLLeitschuh commented Sep 19, 2018

null as String will fail to cast (at runtime) I think. Does null as? String work or does it give the same error as @jnizet was experiencing?

@eskatos
Copy link
Member

eskatos commented Nov 6, 2018

@JLLeitschuh, yes, same error

@jnizet, that's a bug in IntelliJ, could you please open a http://kotl.in/issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants