-
Notifications
You must be signed in to change notification settings - Fork 495
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
Kotlin anonymous classes provoke errors #420
Comments
I'm not able to debug the agent, but I was able to modify the code and see what was inside the pool. And on this very reduced reproducer, the class is not in the pool
|
Also when developing within IJ for some reasons I had an issue with the
|
From anonymous class plugin's point of view all code must published to class path before redefinition is called. I have noticed a problem with it, when IDE called redefinition before all compilation is synchronized to class path, may be it is the same problem. In my case there was a new class, that did not exist before. |
I don't think this is the case here. The Lines 97 to 98 in 322b3f7
However it seems that Hence it seems that indeed the class |
I have played a bit with kotlin, and discovered they have backticked identifiers. So So for example the code below will produce these classes :
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
fun main(args: Array<String>) {
Executors.newSingleThreadScheduledExecutor()
.scheduleAtFixedRate(
Runnable {
print(Reproducer().`$$a white - space`())
print(" ; ")
println(Reproducer().o)
},
2,
2,
TimeUnit.SECONDS
)
}
class Reproducer {
val o = object {
override fun toString(): String {
return "foo-bar-qux"
}
}
fun `$$a white - space`(): Any {
val o = object {
override fun toString(): String {
return "foo bar"
}
}
return o
}
} So I have made a simple algorithm to find the Kotlin enclosing class: @@ -101,6 +101,15 @@ public class AnonymousClassPatchPlugin {
if (classPool.find(className) == null)
return null;
+ while (classPool.find(mainClass) == null) {
+ // identifiers like this are possible in Kotlin
+ // - val `$$$something` = 1
+ // - val `a white space and a dash -`() { }
+ mainClass = mainClass.substring(0, mainClass.lastIndexOf('$'));
+ System.err.println("Infer mainclass, trying " + mainClass);
+ }
+
AnonymousClassInfos info = getStateInfo(classLoader, classPool, mainClass);
String compatibleName = info.getCompatibleTransition(javaClass); With this change the NPE is gone, however now the replacement does not behave as expected. eg, if I change Runnable {
print(Reproducer().`$$a white - space`())
- print(" ; ")
+ print(" # ")
println(Reproducer().o)
}, The program don't print the correct toString
|
I wondered if this last bit was something particular to the import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import javax.swing.JLabel
fun main(args: Array<String>) {
Executors.newSingleThreadScheduledExecutor()
.scheduleAtFixedRate(
Runnable {
print(Reproducer().`$$a white - space`().text)
print(" - ")
println(Reproducer().o.text)
},
2,
2,
TimeUnit.SECONDS
)
}
class Reproducer {
val o = object : JLabel() {
override fun getText(): String {
return "Hello from o"
}
}
fun `$$a white - space`(): JLabel {
val o = object : JLabel() {
override fun getText(): String {
return "Hello from white space"
}
}
return o
}
} Again just changing this line Runnable {
print(Reproducer().`$$a white - space`())
- print(" ; ")
+ print(" # ")
println(Reproducer().o)
}, Produces this
It's like the method overrides of the anonymous class are gone. |
Using a recent version HotswapPlugin (compiled from head a few weeks ago), I need to disable the AnonymousClassPatch plugin for any projects using Kotlin. Is this the only option at this point, or do others have any fixes or workarounds? Thanks for any pointers! |
As far as the issue causing the NullPointerException in the |
Amazing news! Thanks so much for all the recent fixes!!! |
I recommend to use also the last jbr17/21 versions since there is fixed following problem: |
This gives the following logs
The classes are here :
The text was updated successfully, but these errors were encountered: