Random code change to prevent JVM crash on windows (JRE version: 6.0_45-b06)
JVM crash log: # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x06b1e0ae, pid=2908, tid=1656 # # JRE version: 6.0_45-b06 # Java VM: Java HotSpot(TM) Client VM (20.45-b01 mixed mode windows-x86 ) # Problematic frame: # J org.jetbrains.kotlin.idea.formatter.KotlinPreFormatProcessor$Visitor.visitNamedDeclaration(Lorg/jetbrains/kotlin/psi/KtNamedDeclaration;)V # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # --------------- T H R E A D --------------- Current thread (0x5f0bb800): JavaThread "AWT-EventQueue-1 IDEA 15.0.4#IC-143.SNAPSHOT IDEA, eap:true, os:Windows Server 2008 R2 6.1, java-version:Sun Microsystems Inc. 1.6.0_45-b06 IDEA 15.0.4#IC-143.SNAPSHOT IDEA, eap:true, os:Windows Server 2008 R2 6.1, java-version:Sun Microsystems Inc. 1.6.0_45-b06" [_thread_in_Java, id=1656, stack(0x60520000,0x60570000)] siginfo: ExceptionCode=0xc0000005, writing address 0x8b8721bf Registers: EAX=0x0b8721c0, EBX=0x0b655c10, ECX=0x00000000, EDX=0x4789df50 ESP=0x6056d620, EBP=0x6056df7c, ESI=0x0b0b3618, EDI=0x0b8721d0 EIP=0x06b1e0ae, EFLAGS=0x00010246 Top of Stack: (sp=0x6056d620) 0x6056d620: 00000006 0b86d8b8 0afd5c68 026112bb 0x6056d630: 0b86f1a6 0b86f1dc 6056e088 05632944 0x6056d640: 00000004 00000000 6056e088 0b86f214 0x6056d650: 00000086 6056d668 6dae8209 0b86f214 0x6056d660: 0b86f074 00000086 6056d8b0 049aec30 0x6056d670: 0b872170 0b655c10 0b871c80 0b0b5210 0x6056d680: 0b0b4df8 0b8721c0 00000005 0b8705c0 0x6056d690: 0afd5c68 0b86eef8 0afd5c68 0b86d8b8 Instructions: (pc=0x06b1e0ae) 0x06b1e08e: b9 0e 00 00 89 79 34 8b 4a 68 89 08 89 50 04 33 0x06b1e09e: c9 89 48 08 89 48 0c 89 44 24 64 b9 00 00 00 00 0x06b1e0ae: 89 88 ff ff ff 7f f0 83 04 24 00 83 fb 00 0f 84 0x06b1e0be: 12 00 00 00 81 7b 04 60 06 0d 45 0f 85 05 00 00 Register to memory mapping: EAX= [error occurred during error reporting (printing register info), id 0xc0000005] Stack: [0x60520000,0x60570000], sp=0x6056d620, free space=309k Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code) J org.jetbrains.kotlin.idea.formatter.KotlinPreFormatProcessor$Visitor.visitNamedDeclaration(Lorg/jetbrains/kotlin/psi/KtNamedDeclaration;)V J com.intellij.psi.impl.source.PostprocessReformattingAspect.doPostponedFormattingInner(Lcom/intellij/psi/FileViewProvider;)V
This commit is contained in:
@@ -28,48 +28,48 @@ import org.jetbrains.kotlin.psi.psiUtil.nextSiblingOfSameType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.prevSiblingOfSameType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.lastIsInstanceOrNull
|
||||
|
||||
class KotlinPreFormatProcessor : PreFormatProcessor {
|
||||
class Visitor(var range: TextRange) : KtTreeVisitorVoid() {
|
||||
private fun PsiElement.containsToken(type: IElementType) = allChildren.any { it.node.elementType == type }
|
||||
private class Visitor(var range: TextRange) : KtTreeVisitorVoid() {
|
||||
override fun visitNamedDeclaration(declaration: KtNamedDeclaration) {
|
||||
fun PsiElement.containsToken(type: IElementType) = allChildren.any { it.node.elementType == type }
|
||||
|
||||
override fun visitNamedDeclaration(declaration: KtNamedDeclaration) {
|
||||
if (!range.contains(declaration.textRange)) return
|
||||
if (!range.contains(declaration.textRange)) return
|
||||
|
||||
val classBody = declaration.parent as? KtClassBody ?: return
|
||||
val klass = classBody.parent as? KtClass ?: return
|
||||
if (!klass.isEnum()) return
|
||||
val classBody = declaration.parent as? KtClassBody ?: return
|
||||
val klass = classBody.parent as? KtClass ?: return
|
||||
if (!klass.isEnum()) return
|
||||
|
||||
var delta = 0
|
||||
var delta = 0
|
||||
|
||||
if (declaration is KtEnumEntry) {
|
||||
val comma = KtPsiFactory(klass).createComma()
|
||||
if (declaration is KtEnumEntry) {
|
||||
val comma = KtPsiFactory(klass).createComma()
|
||||
|
||||
declaration.nextSiblingOfSameType()?.let { nextEntry ->
|
||||
if (declaration.containsToken(KtTokens.COMMA)) return@let
|
||||
classBody.addAfter(comma, declaration)
|
||||
delta += comma.textLength
|
||||
}
|
||||
|
||||
declaration.prevSiblingOfSameType()?.let { prevEntry ->
|
||||
if (prevEntry.containsToken(KtTokens.COMMA)) return@let
|
||||
classBody.addAfter(comma, prevEntry)
|
||||
delta += comma.textLength
|
||||
}
|
||||
}
|
||||
else {
|
||||
val lastEntry = klass.declarations.lastIsInstanceOrNull<KtEnumEntry>()
|
||||
if (lastEntry != null && lastEntry.containsToken(KtTokens.SEMICOLON)) return
|
||||
if (lastEntry == null && classBody.containsToken(KtTokens.SEMICOLON)) return
|
||||
|
||||
val semicolon = KtPsiFactory(klass).createSemicolon()
|
||||
classBody.addAfter(semicolon, lastEntry)
|
||||
delta += semicolon.textLength
|
||||
declaration.nextSiblingOfSameType()?.let { nextEntry ->
|
||||
if (declaration.containsToken(KtTokens.COMMA)) return@let
|
||||
classBody.addAfter(comma, declaration)
|
||||
delta += comma.textLength
|
||||
}
|
||||
|
||||
range = TextRange(range.startOffset, range.endOffset + delta)
|
||||
declaration.prevSiblingOfSameType()?.let { prevEntry ->
|
||||
if (prevEntry.containsToken(KtTokens.COMMA)) return@let
|
||||
classBody.addAfter(comma, prevEntry)
|
||||
delta += comma.textLength
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
val lastEntry = klass.declarations.lastIsInstanceOrNull<KtEnumEntry>()
|
||||
if (lastEntry != null && lastEntry.containsToken(KtTokens.SEMICOLON)) return
|
||||
if (lastEntry == null && classBody.containsToken(KtTokens.SEMICOLON)) return
|
||||
|
||||
val semicolon = KtPsiFactory(klass).createSemicolon()
|
||||
classBody.addAfter(semicolon, lastEntry)
|
||||
delta += semicolon.textLength
|
||||
}
|
||||
|
||||
range = TextRange(range.startOffset, range.endOffset + delta)
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinPreFormatProcessor : PreFormatProcessor {
|
||||
override fun process(element: ASTNode, range: TextRange): TextRange {
|
||||
val psi = element.psi ?: return range
|
||||
if (!psi.isValid) return range
|
||||
|
||||
Reference in New Issue
Block a user