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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixed Kotlin/Java projects can produce classes that crash the tool due to strange class names #1883

Closed
studro opened this issue Dec 19, 2021 · 1 comment · Fixed by #1884
Closed

Comments

@studro
Copy link
Contributor

studro commented Dec 19, 2021

When running the spotbugs gradle task in a mixed Kotlin/Java project, the task may fail due to the presence of classes containing special characters in their binary name. This is due to Kotlin allowing identifiers (including method names) to be backtick-quoted.

An example of such a class might be (in binary / slashed name format):

com/bla/TestClass$this test calls run() successfully$obj$1"

This class would be an anonymous class existing in the TestClass class in the com.bla package, which is assigned in the `this test calls run()` method, assigned to the obj variable. The rough code that would produce this in Kotlin would be:

package com.bla

// ...
class TestClass{

    // ...
    fun `this test calls run() successfully`() {
        // ...
        var obj = object {}
        // ...
    }
// ...
}

where the var obj = object {} produces the anonymous inner class.

This Kotlin Playground example shows the described class naming in action.

I've identified the root cause of this issue being the edu.umd.cs.findbugs.util.ClassName.isValidClassName(String) method not implementing proper name validation in accordance with section 4.2 of the Java Virtual Machine specification. It appears that this method is being used in a number of different ways and must support all of the following inputs:

  • dotted class names,
  • binary (slashed) class names, and
  • field descriptors.

I've made two commits in the PR that I will attach to this issue:

  • the first adds test coverage showing the current behaviour and expected behaviour (with some tests failing).
  • the second makes changes to the isValidClassName() method to make the tests pass.
@welcome
Copy link

welcome bot commented Dec 19, 2021

Thanks for opening your first issue here! 😃
Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in 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
1 participant