mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 11:53:49 +07:00
[java-runner] IJ-CR-154797 IDEA-363985 Temporary workaround for JNI restriction
(cherry picked from commit 636caa3aaf46f8bbe6b37ca474662bb95f705f97) GitOrigin-RevId: dda8badbd17ef8a6f23930282779e482f12c10e4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3d43f7077c
commit
85d38f47ea
@@ -784,6 +784,7 @@
|
||||
<lang.smartEnterProcessor language="JSPX" implementationClass="com.intellij.codeInsight.completion.XmlSmartEnterProcessor"/>
|
||||
|
||||
<iconProvider implementation="com.intellij.execution.testframework.TestIconProvider" id="testIcons"/>
|
||||
<console.folding implementation="com.intellij.execution.JavaRunnerRestrictedMethodCallConsoleFolding"/>
|
||||
<stacktrace.fold.line.modifier implementation="com.intellij.execution.JavaModuleNameStacktraceModifier"/>
|
||||
<stacktrace.fold substring="at java.awt.EventDispatchThread"/>
|
||||
<stacktrace.fold substring="at java.awt.Window.dispatchEventImpl("/>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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.execution;
|
||||
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A specialized implementation of the {@link ConsoleFolding} class designed to handle
|
||||
* the folding of console lines that represent warnings related to restricted method calls of java runner.
|
||||
* This is a temporary solution until IDEA starts using signals
|
||||
*
|
||||
* @deprecated will be deleted when IDEA starts using signals
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(forRemoval = true)
|
||||
public class JavaRunnerRestrictedMethodCallConsoleFolding extends ConsoleFolding {
|
||||
private static final List<String> RESTRICTED_CALL_WARNING = List.of(
|
||||
"WARNING: A restricted method in java.lang.System has been called",
|
||||
"WARNING: java.lang.System::load has been called by com.intellij.rt.execution.application.AppMainV2 in an unnamed module",
|
||||
"WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module",
|
||||
"WARNING: Restricted methods will be blocked in a future release unless native access is enabled"
|
||||
);
|
||||
|
||||
@Override
|
||||
public boolean shouldFoldLine(@NotNull Project project, @NotNull String line) {
|
||||
return ContainerUtil.or(RESTRICTED_CALL_WARNING, line::startsWith);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeAttachedToThePreviousLine() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getPlaceholderText(@NotNull Project project, @NotNull List<@NotNull String> lines) {
|
||||
if (lines.size() == RESTRICTED_CALL_WARNING.size() &&
|
||||
StreamEx.of(RESTRICTED_CALL_WARNING).zipWith(lines.stream())
|
||||
.allMatch(pair -> pair.getValue().startsWith(pair.getKey()))) {
|
||||
return JavaBundle.message("restricted.system.load.is.used");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// 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.execution.impl;
|
||||
|
||||
import com.intellij.execution.JavaRunnerRestrictedMethodCallConsoleFolding;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JavaRunnerRestrictedMethodCallConsoleFoldingTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
public void testFold() {
|
||||
String actualText = """
|
||||
WARNING: A restricted method in java.lang.System has been called
|
||||
WARNING: java.lang.System::load has been called by com.intellij.rt.execution.application.AppMainV2 in an unnamed module (file:/C:/projects-idea/intellij/out/classes/production/intellij.java.rt/)
|
||||
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
|
||||
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
|
||||
""";
|
||||
List<String> lines = StringUtil.split(actualText, "\n");
|
||||
JavaRunnerRestrictedMethodCallConsoleFolding consoleFolding = new JavaRunnerRestrictedMethodCallConsoleFolding();
|
||||
for (String line : lines) {
|
||||
assertTrue(consoleFolding.shouldFoldLine(getProject(), line));
|
||||
}
|
||||
assertNotNull(consoleFolding.getPlaceholderText(getProject(), lines));
|
||||
}
|
||||
|
||||
public void testNotFold() {
|
||||
String actualText = """
|
||||
WARNING: A restricted method in java.lang.System has been called
|
||||
WARNING: java.lang.System::load has been called by com.intellij.rt.execution.application.AppMainV in an unnamed module (file:/C:/projects-idea/intellij/out/classes/production/intellij.java.rt/)
|
||||
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
|
||||
WARNING: Restricted methods will be blocked in a future release unless native access is enabled
|
||||
""";
|
||||
List<String> lines = StringUtil.split(actualText, "\n");
|
||||
JavaRunnerRestrictedMethodCallConsoleFolding consoleFolding = new JavaRunnerRestrictedMethodCallConsoleFolding();
|
||||
assertNull(consoleFolding.getPlaceholderText(getProject(), lines));
|
||||
}
|
||||
}
|
||||
@@ -1956,4 +1956,6 @@ checkbox.check.for.jdk.updates=Check for JDK updates
|
||||
intention.family.name.rename.to.ignored=Rename to ignored
|
||||
tooltip.variable.used=Variable ''{0}'' is used
|
||||
|
||||
advanced.setting.java.show.irrelevant.templates.in.source.roots=Show irrelevant New File templates in Java source roots
|
||||
advanced.setting.java.show.irrelevant.templates.in.source.roots=Show irrelevant New File templates in Java source roots
|
||||
|
||||
restricted.system.load.is.used=System::load is used
|
||||
|
||||
Reference in New Issue
Block a user