From 86210e4506d070dcfbabd8bc992a4babe3cf8426 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 26 Sep 2025 16:32:48 +0200 Subject: [PATCH] Java: avoid exception and broken code in compact source file (IDEA-379938) GitOrigin-RevId: b0846f84f6830ce49bcf0ab5974e864c8d41f75b --- ...AddExceptionFromFieldInitializerToConstructorThrowsFix.java | 3 ++- .../quickFix/addToConstructorThrows/beforeImplicitClass.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addToConstructorThrows/beforeImplicitClass.java diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddExceptionFromFieldInitializerToConstructorThrowsFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddExceptionFromFieldInitializerToConstructorThrowsFix.java index de385493ca1a..588573fa0046 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddExceptionFromFieldInitializerToConstructorThrowsFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddExceptionFromFieldInitializerToConstructorThrowsFix.java @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.ExceptionUtil; @@ -37,6 +37,7 @@ public final class AddExceptionFromFieldInitializerToConstructorThrowsFix extend final PsiClass containingClass = field.getContainingClass(); if (containingClass == null || containingClass instanceof PsiAnonymousClass || + containingClass instanceof PsiImplicitClass || containingClass.isInterface()) { return null; } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addToConstructorThrows/beforeImplicitClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addToConstructorThrows/beforeImplicitClass.java new file mode 100644 index 000000000000..686c4f7935ac --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/addToConstructorThrows/beforeImplicitClass.java @@ -0,0 +1,3 @@ +// "Add exception to constructor signature" "false" + +java.io.FileWriter fw = new java.io.FileWriter("sunshine");