https://kotlinlang.org logo
Title
l

LastExceed

12/09/2019, 2:32 PM
im getting a compile error that i dont understand:

https://i.imgur.com/6kNkSRr.png

it says "unresolved reference" even though in the editor it seems to be recognized just fine, it shows up in autocomplete and i can navigate to the implementation just fine. whats going on here?
s

Sergei Dubrov [JB]

12/09/2019, 2:43 PM
Hi! I checked with the easiest sample and issue does not reproduce:
import javax.sound.sampled.AudioInputStream

fun test(ais: AudioInputStream) {
    ais.readNBytes(ais.available()) // compiles fine
}
Can you send a code example?
l

LastExceed

12/09/2019, 2:43 PM
I'll try to narrow it down
a

Alex Crafford

12/09/2019, 2:47 PM
I see this happen in Android Studio on occasion and normally Invalidate and Restart does the trick.
l

LastExceed

12/09/2019, 2:48 PM
import <http://java.io|java.io>.ByteArrayInputStream
import <http://java.io|java.io>.ByteArrayOutputStream
import javax.sound.sampled.*
import kotlin.concurrent.thread

fun main() {
    val format = AudioFormat(
        192000f,
        16,
        1,
        true,
        true
    )
    val info = <http://DataLine.Info|DataLine.Info>(TargetDataLine::class.java, format)
    if (!AudioSystem.isLineSupported(info)) {
        error("Line not supported")
    }
    val line = AudioSystem.getLine(info) as TargetDataLine
    line.open(format)
    line.start()
    println("Start capturing...")

    val ais = AudioInputStream(line)
    val baos = ByteArrayOutputStream()
    var stop = false
    thread {
        Thread.sleep(3000)
        stop = true
    }
    while (!stop) {
        val buffer = ais.readNBytes(ais.available())
        //workaround: 
        //val buffer = ByteArray(ais.available())
        //ais.read(buffer)
        baos.write(buffer)
    }
    line.stop()
    line.close()
    println("done")
    val recorded = AudioInputStream(ByteArrayInputStream(baos.toByteArray()), format, baos.size().toLong())


    readLine()

    val clip = AudioSystem.getClip()
    clip.open(recorded)
    clip.start()
}
records 3 seconds audio, then plays it back after pressing enter. i found a workaround but i'd still like to understand the error
IDE restart or gradle-reimport didnt fix it
s

Sergei Dubrov [JB]

12/09/2019, 2:49 PM
Build is successful for this example in my case.
Are you getting a compile error?
l

LastExceed

12/09/2019, 2:50 PM
all i get is whats shown on the screenshot
s

Sergei Dubrov [JB]

12/09/2019, 2:53 PM
can you share your build.gradle?
l

LastExceed

12/09/2019, 2:53 PM
plugins {
    kotlin("jvm") version "1.3.61"
}

group = "lastexceed"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    compile(files("src/main/resources/jnativehook-2.1.0.jar"))
}

tasks {
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
}
s

Sergei Dubrov [JB]

12/09/2019, 2:59 PM
Still unable to reproduce. Seems to be some sporadic bug. Can you attach your project?
l

LastExceed

12/09/2019, 3:00 PM
alright sec
j

Jamie Taylor

12/09/2019, 3:05 PM
Could it be a java version issue? readNBytes was only introduced in Java 9.
l

LastExceed

12/09/2019, 3:05 PM
i use 13.0.1
s

Sergei Dubrov [JB]

12/09/2019, 3:23 PM
It compiles fine at my site. Did you try
Shift+Shift -> Invalidate Caches / Restart...
?
l

LastExceed

12/09/2019, 3:23 PM
not yet, gonna try that now
didn't help
s

Sergei Dubrov [JB]

12/09/2019, 3:28 PM
Ok, lets go on. 😃 Attach please "File -> Export Settings...". And I'll try to compile with Java 13.0.1
l

LastExceed

12/09/2019, 3:30 PM
there is no "export settings" option for me

https://i.imgur.com/QxiS4wB.png

or am i blind?
s

Sergei Dubrov [JB]

12/09/2019, 3:32 PM
just a sec
l

LastExceed

12/09/2019, 3:37 PM
ah yes thats probably it
🆒 1
how do i disable it?
nvm found it
s

Sergei Dubrov [JB]

12/09/2019, 3:47 PM
Compiles fine with Oracke JDK 13.0.1
Problem seems to be with AdoptOpenJDK
l

LastExceed

12/09/2019, 3:48 PM
were you able to reproduce?
with AdpotOpenJDK i mean
s

Sergei Dubrov [JB]

12/09/2019, 3:48 PM
not yet. downloading it now
Also compiled successfully
l

LastExceed

12/09/2019, 3:53 PM
(╯°□°)╯︵ ┻━┻
s

Sergei Dubrov [JB]

12/09/2019, 3:54 PM
The only difference I see now is My AdoptOpenJDK installation folder named jdk-13.0.1.9-hotspot and yours is jdk-13.0.1+9
Can you try to re-compile this code with different jdk?
l

LastExceed

12/09/2019, 3:55 PM
i can, which should i use?
s

Sergei Dubrov [JB]

12/09/2019, 3:59 PM
e.q. one by Oracle
Also what is your Windows version?
And Idea version (Help -> About)?
l

LastExceed

12/09/2019, 4:00 PM
windowsVersion 10.0.18363 Build 18363
IDEA 2019.3 build 193.5233.102
btw is it normal that it says
implementation(kotlin("stdlib-jdk8"))
and
kotlinOptions.jvmTarget = "1.8"
in the build.gradle even though the project jdk is 1.13 and not 1.8 ? (not that familiar with this stuff)
s

Sergei Dubrov [JB]

12/09/2019, 4:03 PM
It is correct. Don't remember why exactly but this it what should be there
l

LastExceed

12/09/2019, 4:04 PM
installed OracleJDK 13.01 now, problem persists
l

LeoColman

12/09/2019, 4:05 PM
Try deleting the .idea folder
When this kiind of thing happens I just delete
.idea
and
Invalidate/Restart
l

LastExceed

12/09/2019, 4:06 PM
done, didnt help
s

Sergei Dubrov [JB]

12/09/2019, 4:12 PM
@LastExceed did you also tried to delete
.idea
folder?
l

LastExceed

12/09/2019, 4:12 PM
yes thats what i just tried
s

Sergei Dubrov [JB]

12/09/2019, 4:13 PM
I can suggest to create a new project and try to do all the same in it. It is definitely some configurational bug.
l

LastExceed

12/09/2019, 4:15 PM
done, didnt help
i created a new project and just pasted the same code from above in it, same error
s

Sergei Dubrov [JB]

12/09/2019, 4:18 PM
magic
@Alexey Belkov [JB] do you have any idea?
🤷 1
@LastExceed did it help to compile with different JDK?
l

LastExceed

12/09/2019, 4:20 PM
no
s

Sergei Dubrov [JB]

12/09/2019, 4:26 PM
What is the second error message is there?
l

LastExceed

12/09/2019, 4:28 PM
i think that was unrelated (when i was still working on the whole project), i dont have that second error now
s

Sergei Dubrov [JB]

12/10/2019, 8:33 AM
@LastExceed If your problem still actual I suggest you to check the same name resolution in Java. In case it does not resolve in Java (actually in any case) I would recommend you to ask IDEA support. They have more experience in such a weird problems.
l

LastExceed

12/10/2019, 11:37 AM
ayy, we're making progress: i re-implemented the code sample in java and now it highlights and error in the editor:
Usage of API documented as @since 11+
which is strange because my project language level is set to 13 (and setting it to 11 doesn't solve it either). HOWEVER the IDE still gave me the suggestion "set language level to 11" and clicking that solved the problem, but I am now oblivious to what was actually the problem since as i said the the project language level was already high enough and I am now unable to reproduce the error anymore even if i create a whole new project like before. I'd really like to understand what's going on here especially since there is definitely something on the Kotlin side that needs to be fixed, can you explain? @Sergei Dubrov [JB]
s

Sergei Dubrov [JB]

12/11/2019, 8:11 AM
Please report a ticket for false positive inspection at https://youtrack.jetbrains.com/issues/IDEA? Regarding the problem with resolve in Kotlin, it is not clear how it can be reproduced. It could also be an IDEA bug. In case you find a way how to do that please report it at https://youtrack.jetbrains.com/issues/KT?.