use top level classId for looking up java classes in KotlinCliJavaFileManagerImpl
diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCliJavaFileManagerImpl.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCliJavaFileManagerImpl.kt
index 3eafef9..914c096 100644
--- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCliJavaFileManagerImpl.kt
+++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinCliJavaFileManagerImpl.kt
@@ -72,7 +72,8 @@
 
     private fun findVirtualFileForTopLevelClass(classId: ClassId, searchScope: GlobalSearchScope): VirtualFile? {
         val relativeClassName = classId.relativeClassName.asString()
-        return topLevelClassesCache.getOrPut(classId.packageFqName.child(classId.relativeClassName.pathSegments().first())) {
+        val outerMostClassFqName = classId.packageFqName.child(classId.relativeClassName.pathSegments().first())
+        return topLevelClassesCache.getOrPut(outerMostClassFqName) {
             // Search java sources first. For build tools, it makes sense to build new files passing all the
             // class files for the previous build on the class path.
             //
@@ -86,8 +87,9 @@
             // we want to make sure that we get the new A.java and not the old version A.class from previous.jar.
             //
             // Otherwise B.kt will not see the newly added field in A.
-            singleJavaFileRootsIndex.findJavaSourceClass(classId)
-                ?: index.findClass(classId) { dir, type ->
+            val outerMostClassId = ClassId.topLevel(outerMostClassFqName)
+            singleJavaFileRootsIndex.findJavaSourceClass(outerMostClassId)
+                ?: index.findClass(outerMostClassId) { dir, type ->
                     findVirtualFileGivenPackage(dir, relativeClassName, type)
                 }