-
Notifications
You must be signed in to change notification settings - Fork 343
Add reflection utility to fix split debugger error #8878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f66c033
Add reflection utility to fix split debugger error
helin24 9c5e43b
Extract helper in utils
helin24 1742c65
Make methods static
helin24 6cfea4e
Catch invocation target exception
helin24 6d40077
Remove unused method
helin24 0bbab34
Add comment with TODO
helin24 75aa8d2
Add issue #
helin24 474365e
Add note to styleguide to check for copyright headers
helin24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Copyright 2026 The Chromium Authors. All rights reserved. | ||
| * Use of this source code is governed by a BSD-style license that can be | ||
| * found in the LICENSE file. | ||
| */ | ||
| package io.flutter.run; | ||
|
|
||
| import com.intellij.execution.ExecutionException; | ||
| import com.intellij.execution.runners.ExecutionEnvironment; | ||
| import com.intellij.execution.ui.RunContentDescriptor; | ||
| import com.intellij.xdebugger.XDebugProcessStarter; | ||
| import com.intellij.xdebugger.XDebugSession; | ||
| import com.intellij.xdebugger.XDebuggerManager; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.lang.reflect.Method; | ||
|
|
||
| // TODO(helin24): This class is using reflection to find experimental APIs that are only present in platform versions 2025.3+. We should be | ||
| // able to use the APIs directly once we are only supporting versions past 2025.3. | ||
|
helin24 marked this conversation as resolved.
|
||
| // See https://github.com/flutter/flutter-intellij/issues/8879. | ||
| public class FlutterDebugSessionUtils { | ||
|
|
||
| private static final Method newSessionBuilderMethod; | ||
| private static final Method environmentMethod; | ||
| private static final Method startSessionMethod; | ||
|
|
||
| static { | ||
| Method nsb = null; | ||
| Method env = null; | ||
| Method ss = null; | ||
| try { | ||
| nsb = XDebuggerManager.class.getMethod("newSessionBuilder", XDebugProcessStarter.class); | ||
| Class<?> builderClass = nsb.getReturnType(); | ||
| env = builderClass.getMethod("environment", ExecutionEnvironment.class); | ||
| ss = builderClass.getMethod("startSession"); | ||
| } catch (NoSuchMethodException e) { | ||
| // Fallback for older platforms | ||
| } | ||
| newSessionBuilderMethod = nsb; | ||
| environmentMethod = env; | ||
| startSessionMethod = ss; | ||
| } | ||
|
|
||
| public static @NotNull RunContentDescriptor startSessionAndGetDescriptor( | ||
| @NotNull XDebuggerManager manager, | ||
| @NotNull ExecutionEnvironment env, | ||
| @NotNull XDebugProcessStarter starter, | ||
| boolean muteBreakpoints) throws ExecutionException { | ||
| try { | ||
| if (newSessionBuilderMethod == null) { | ||
| throw new NoSuchMethodException("newSessionBuilder is not available"); | ||
| } | ||
| Object builder = newSessionBuilderMethod.invoke(manager, starter); | ||
| builder = environmentMethod.invoke(builder, env); | ||
| Object sessionResult = startSessionMethod.invoke(builder); | ||
|
|
||
| if (muteBreakpoints) { | ||
| Method getSessionMethod = sessionResult.getClass().getMethod("getSession"); | ||
| XDebugSession session = (XDebugSession) getSessionMethod.invoke(sessionResult); | ||
| session.setBreakpointMuted(true); | ||
| } | ||
|
|
||
| Method getDescriptorMethod = sessionResult.getClass().getMethod("getRunContentDescriptor"); | ||
| return (RunContentDescriptor) getDescriptorMethod.invoke(sessionResult); | ||
|
|
||
| } catch (NoSuchMethodException e) { | ||
| // Fallback to old API for 2025.1 and older | ||
| XDebugSession session = manager.startSession(env, starter); | ||
| if (muteBreakpoints) { | ||
| session.setBreakpointMuted(true); | ||
| } | ||
| return session.getRunContentDescriptor(); | ||
| } catch (InvocationTargetException e) { | ||
| Throwable cause = e.getCause(); | ||
| if (cause instanceof ExecutionException) { | ||
| throw (ExecutionException) cause; | ||
| } | ||
| throw new ExecutionException("Failed to start debug session via reflection", cause != null ? cause : e); | ||
| } catch (Exception e) { | ||
| throw new ExecutionException("Failed with unexpected reflection error", e); | ||
| } | ||
|
helin24 marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.