Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any plans to support kotlin? #573

Closed
Aditya94A opened this issue Feb 27, 2018 · 13 comments
Closed

Any plans to support kotlin? #573

Aditya94A opened this issue Feb 27, 2018 · 13 comments

Comments

@Aditya94A
Copy link

馃榿

@ice1000
Copy link

ice1000 commented Mar 1, 2018

I tried using this to analyze my kotlin codes, no effect. Only bugs in Java codes are displayed.

@h3xstream
Copy link
Member

h3xstream commented May 7, 2018

I have been developing in Kotlin for few projects. Looking at the bytecode, I would say that this JVM language is by far the easiest to support if compare to Scala or Groovy.

  • Add analog API to specified in detectors that need it.
  • Modify plugins for IDE and CI would need to implements a multi-languages support.

@davidgoate
Copy link

davidgoate commented May 21, 2018

@ice1000 you say

I tried using this to analyze my kotlin codes, no effect

For some reason I do have effects from this, just not ones I desired.

On this input class:

data class CSVRecord(private val columns: SortedSet<CSVColumn>) : Iterable<String> {

    override fun iterator(): Iterator<String> {
        return columns.map { it.value }.iterator()
    }
}

I get:

ERROR] Private method com.example.CSVRecord.component1() is never called [com.example.CSVRecord] In CSVRecord.kt UPM_UNCALLED_PRIVATE_METHOD

and many instances of Questionable cast from Collection to abstract class java.util.List (BC_BAD_CAST_TO_ABSTRACT_COLLECTION). On code such as:

override fun iterator(): Iterator<String> {
        return columns.map { it.value }.iterator()
    }

Not sure whether the latter is actually my mistake or not.

@jolkdarr
Copy link
Contributor

Hi
FYI, there is a tool that may help to analyse Kotlin files:
https://github.com/arturbosch/detekt

@xenoterracide
Copy link
Contributor

detekt says it uses the kotlin parse tree, where spotbugs is bytecode analysis.

sschuberth added a commit to bosch-io/antenna that referenced this issue Sep 23, 2019
Spotbugs does not support Kotlin yet and still running it results in
bogus violations being reported.

Also see spotbugs/spotbugs#573.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
sschuberth added a commit to bosch-io/antenna that referenced this issue Sep 23, 2019
Spotbugs does not support Kotlin yet and still running it results in
bogus violations being reported.

Also see spotbugs/spotbugs#573.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
sschuberth added a commit to bosch-io/antenna that referenced this issue Sep 24, 2019
Spotbugs does not support Kotlin yet and still running it results in
bogus violations being reported.

Also see spotbugs/spotbugs#573.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
@dnsbtchr
Copy link

dnsbtchr commented May 6, 2021

Hey, any news in this area? We use the find-sec-bugs plugin and would love to use it for our Kotlin projects as well.

@ThrawnCA
Copy link
Contributor

ThrawnCA commented May 6, 2021

Theoretically it is possible to run SpotBugs on any Java bytecode. In practice, Kotlin probably generates patterns that SpotBugs doesn't like, but you could probably just write exclusion rules for them.

@dnsbtchr
Copy link

dnsbtchr commented May 7, 2021

So I just ran SpotBugs with it's Maven plugin on a project which contains Java and Kotlin. I added Java class with a know bug pattern from the findsecbugs plugin to the project and SpotBugs complained about it (as I expected it to). Then I converted the same class to Kotlin and it didn't complain. Is that the expected behaviour? From your answer I'd rather expect it to complain maybe about other weird things on top of the actual issue or did I get that wrong? 馃

@ThrawnCA
Copy link
Contributor

ThrawnCA commented May 7, 2021

Depends on exactly what byte code it generated. Maybe Kotlin avoids whatever the bug was?

@dnsbtchr
Copy link

dnsbtchr commented May 7, 2021

I doubt it because I used this code and I don't know what Kotlin could do to prevent the issue.
String generateSecretToken() { Random r = new Random(); return Long.toHexString(r.nextLong()); }
It's from https://find-sec-bugs.github.io/bugs.htm#PREDICTABLE_RANDOM

@gtoison
Copy link
Contributor

gtoison commented Jun 19, 2022

If anyone is interested I've got a pull request to use SpotBugs to analyze Kotlin in the SonarQube plugin; spotbugs/sonar-findbugs#569
I've tested by analyzing the https://github.com/detekt/detekt and https://github.com/jitsi/jitsi-videobridge projects and the issues detected seem to make sense for the most part.
I don't know Kotlin so it would be appreciated if anyone could try this out and give feedback, please let me know if you're interested.

The tricky part is that due to the Kotlin compilation process, the bytecode in a .class file might be from different source files, so I needed to analyse the SMAP section to find which line comes from which source file (and the corresponding line).
In particular SpotBugs detects a lot of issues in bytecode that is actually from the Kotlin arrays and collections built-in classes.

@tianyu
Copy link

tianyu commented Sep 11, 2023

For what it's worth, I tried it out and spotbugs seems to work: https://github.com/tianyu/spotbugs-with-kotlin

@gtoison
Copy link
Contributor

gtoison commented Sep 12, 2023

Thanks for the feedback!
Unless someone thinks otherwise I suppose that we can close this issue.

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

No branches or pull requests