New J2K: fix UninitializedPropertyAccessException when calculating type of anonymous class
#KT-35395 fixed
This commit is contained in:
@@ -78,6 +78,13 @@ class JKTypeFactory(val symbolProvider: JKSymbolProvider) {
|
||||
JKClassType(JKUnresolvedClassSymbol(type.rawType().canonicalText, this), parameters)
|
||||
is PsiTypeParameter ->
|
||||
JKTypeParameterType(symbolProvider.provideDirectSymbol(target) as JKTypeParameterSymbol)
|
||||
is PsiAnonymousClass -> {
|
||||
/*
|
||||
If anonymous class is declared inside the converting code, we will not be able to access JKUniverseClassSymbol's target
|
||||
And get UninitializedPropertyAccessException exception, so it is ok to use base class for now
|
||||
*/
|
||||
createPsiType(target.baseClassType)
|
||||
}
|
||||
else -> {
|
||||
JKClassType(
|
||||
target.let { symbolProvider.provideDirectSymbol(it) as JKClassSymbol },
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
interface Foo {
|
||||
}
|
||||
|
||||
public class Bar {
|
||||
void test() {
|
||||
new Foo() {
|
||||
void foo() {
|
||||
bug(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void bug(Foo foo) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// ERROR: 'public' function exposes its 'internal' parameter type Foo
|
||||
internal interface Foo
|
||||
class Bar {
|
||||
fun test() {
|
||||
object : Foo {
|
||||
fun foo() {
|
||||
bug(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bug(foo: Foo?) {}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
public class Foo {
|
||||
|
||||
void fail() {
|
||||
new Test.FrameCallback() {
|
||||
public void doFrame() {
|
||||
new Test().postFrameCallbackDelayed(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Test {
|
||||
public interface FrameCallback {
|
||||
void doFrame();
|
||||
}
|
||||
|
||||
void postFrameCallbackDelayed(Test.FrameCallback callback) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import Test.FrameCallback
|
||||
|
||||
class Foo {
|
||||
fun fail() {
|
||||
object : FrameCallback {
|
||||
override fun doFrame() {
|
||||
Test().postFrameCallbackDelayed(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class Test {
|
||||
interface FrameCallback {
|
||||
fun doFrame()
|
||||
}
|
||||
|
||||
fun postFrameCallbackDelayed(callback: FrameCallback?) {}
|
||||
}
|
||||
+10
@@ -4027,6 +4027,16 @@ public class NewJavaToKotlinConverterSingleFileTestGenerated extends AbstractNew
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("AccesssThisInsideAnonClass.java")
|
||||
public void testAccesssThisInsideAnonClass() throws Exception {
|
||||
runTest("nj2k/testData/newJ2k/objectLiteral/AccesssThisInsideAnonClass.java");
|
||||
}
|
||||
|
||||
@TestMetadata("AccesssThisInsideAnonClass2.java")
|
||||
public void testAccesssThisInsideAnonClass2() throws Exception {
|
||||
runTest("nj2k/testData/newJ2k/objectLiteral/AccesssThisInsideAnonClass2.java");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInObjectLiteral() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("nj2k/testData/newJ2k/objectLiteral"), Pattern.compile("^([^\\.]+)\\.java$"), null, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user