Skip to content

(simplified) Do not return null editor input from the ClassFileEditorInputFactory#2353

Closed
laeubi wants to merge 1 commit into
eclipse-jdt:masterfrom
laeubi:no_null_simple
Closed

(simplified) Do not return null editor input from the ClassFileEditorInputFactory#2353
laeubi wants to merge 1 commit into
eclipse-jdt:masterfrom
laeubi:no_null_simple

Conversation

@laeubi

@laeubi laeubi commented Jul 18, 2025

Copy link
Copy Markdown
Contributor

Currently ClassFileEditorInputFactory return null in cases when restoring an editor input from an IMemento and the class is not found on the (current) classpath of the project. This prevents the editor from showing up and results in a generic error message instead and prevents proper handling of the case in the editor.

This now in case of an element not found by the project an InternalClassFileEditorInput is returned as we actually have the class data there. The editor can then further handel the case much better.

Currently ClassFileEditorInputFactory return null in cases when
restoring an editor input from an IMemento and the class is not found on
the (current) classpath of the project. This prevents the editor from
showing up and results in a generic error message instead and prevents
proper handling of the case in the editor.

This now in case of an element not found by the project an
InternalClassFileEditorInput is returned as we actually have the class
data there. The editor can then further handel the case much better.
@iloveeclipse

Copy link
Copy Markdown
Member

I don't see any difference to the original behavior in the use case below (original one from #2245).

  • Create a plugin project
  • Add any plugin as a plugin dependency to the MANIFEST.MF (for example: org.eclipse.jface)
  • Navigate to the newly created Project in the Package Explorer
  • Expand "Plug-in Dependencies"
  • Find the newly introduced depencies entry and open any class file in the ClassFileEditor (it just must be a class inside the -Plug-in Dependencies container)
  • Restart Eclipse

I test it by creating a breakpoint at org.eclipse.pde.internal.core.RequiredPluginsInitializer.DeferredClasspathContainerInitializerJob.run(IProgressMonitor).
If this breakpoint is set, I still see exact same picture like before: "The class file is not on the classpath".

Can you please provide steps to verify what the patch is doing?

@laeubi

laeubi commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

If this breakpoint is set, I still see exact same picture like before: "The class file is not on the classpath".

Please compare with the Picture from the report:

grafik

it says ClassFileEditorInputFactory returned null and is the generic ErrorEditor (no stacktrace provided).

Now its is "The class file is not on the classpath" and it is the ClassFileEditor actually showing an error (with stack trace), so we are beyond the case where the init of the Editor fails altogether:

grafik

@iloveeclipse

Copy link
Copy Markdown
Member

I compare with master of JDT UI and see no difference.

@laeubi

laeubi commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

The please check if you hit this code path:

https://github.com/laeubi/eclipse.jdt.ui/blob/0c096b13e08e5207a06c95bc35a862627a3d7afc/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/ClassFileEditorInputFactory.java#L64

that is what #2245 complains and I can reproduce it with a single project in the workspace started from Eclipse directly.

"The class file is not on the classpath" is a different one and I would address this individually.

What I did was:

  1. Launch a new Eclipse from empty workspace (without workspace chooser dialog)
  2. Create a new Plugin Project, when asked switch to plugin perspective and add a required bundle
  3. Now go to Required Plugin Container, expand the jar and open a Class file
  4. Now shutdown and start again --> I see the error from Editor is not restored leading to ClassFileEditorInputFactory returned null error #2245

No breakpoints or similar required.

@laeubi

laeubi commented Jul 18, 2025

Copy link
Copy Markdown
Contributor Author

I still see exact same picture like before: "The class file is not on the classpath".

I created PR to handle the case here:

@laeubi

laeubi commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

@mehmet-karaman I think this one should be merged as a first PR so we get rid of this nasty error about null editor input.

}
//if not found on the project still return an input
//so it can be handled by the editor
return new InternalClassFileEditorInput(cf);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will bring back https://bugs.eclipse.org/bugs/show_bug.cgi?id=83221.
Have you tried this case: same bundle from two different platform states.
The bundle is dependency of a workspace plugin project.
Start with platform IBuild_1, open class from that bundle, exit Eclipse.
Change launch config to use bundle version from platform IBuild_2 & start Eclipse.
What would happen? If we show class bytes, we have similar problem to https://bugs.eclipse.org/bugs/show_bug.cgi?id=83221 again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iloveeclipse I must confess we are running in circles again, yes this will bring back "The classfile is not on the classpath" but this is intentional. Beside that even though Bug 83221 shows the same message the reason is different, anyways this is fixed with

so if you want that one to be merged first, I'm fine with that... we just need to solve one thing to break out of the cycle.

But me and @mehmet-karaman see this null pointer problem and that also what is complained in the initial report in JDT.ui ... I could also merge two PRs if it feels "better".

I also don't see how it could be better to run into a generic null problem than showing a proper message this is a bit out of scope here. So I understand Bug 83221 that it more fixes the issue with a changed classpath location then one where the file is absent all together.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it would be better to start from scratch:

  • close all the PR's that are flying around (I count 4?), because each in isolation seem not to solve a problem we want to solve, and if partially merged they seem not to have much value or probably would rather make things worse.
  • create one PR that solves the original problem - the class editor belongs to a platform bundle, the class file and the bundle exist in the target platform, we don't want to see error nor class bytes, we want to see source code on startup (but because of delayed PDE init can't be found by JDT UI at the startup time).
  • On one of the PR's you've mentioned that the new input classes you introduced in some PR's were actually not needed, if that is the case, it would make sense to remove them.
  • We can address all other issues you've mentioned (deleted classes, missing class files for some reasons, missing sources, show class bytes if there are no sources, whatever else) in different PR's once the original issue is solved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is only one "original issue" and that is

this PR fixes the problem.

Everything else are just follow ups that solve different problems!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR fixes the problem.

This PR doesn't fix it, I still see error editor and not the source of the previously opened class file.

See #2353 (comment) with steps to reproduce.

Here once again, with extra details to make sure we are testing same thing:

  • Close org.eclipse.jface plugin project if you have it opened in the debugger
  • In an empty workspace in debuggee Eclipse
  • Create a simple plugin project
  • Add org.eclipse.jface plugin as a plugin dependency to the MANIFEST.MF
  • Switch to the Java perspective (default one, no extra views opened)
  • Open ILabelProvider via "Open Type" (should be one single hit and it should show up in the Package Explorer under Plug-In dependencies of the bundle just created).
  • Restart Eclipse
  • Now an error part is shown, not the class file editor with source.

Probably you are misguided by some specific setup you have, or some specific class that always resolves for you, or some other bundles/projects in debuggee workspace.

I use plain SDK & plain local target with no m2e or other plugins that might affect classpath or target resolving in either way, and a single plugin bundle project in the workspace. Add JFace as dependency to the bundle and open few JFace classes like ILabelProvider etc. JFace project must be closed in the debugger workspace, so that the runtime sees bundle as a jar and not as a classpath directory faked by PDE. Before closing Eclipse, the editor is opened on the class file

To exclude the possibility it has something with the other dependencies resolving, I've also tried with a dummy bundle with two interfaces exported, I've exported that as deployable bundle to a directory along with sources and added the directory to the target platform, same effect (no improvement at all).

Note 1: you do not need the breakpoint, in most cases the PDE job is initialized classpath container after JDT UI wants to restore the editor. Breakpoint is there to guarantee the bug is reproducible independently on timing of your worksatation.

Note 2: #2351 sometimes fixes that (highly dependent on timing or something else, I guess JDT model events the code expects aren't always sent as expected). In most cases it also doesn't work, and simply disassembled code is shown... There is also an interesting side effect, that if the the first (shown) editor is not properly restored and shows only bytecode, opening any other Java file from same project and switching back to the .class editor shows back the sources but funny enough, it doesn't restore the breadcrumb, which is sometimes shown after some editor switches.

Note 3: you can be sure we are talking about same issue if after the startup that shows the "error" class file, same type can be opened via "Open Type" and opened class editor shows properly rendered Java code. That is what #2245 about. The class is there, the dependency is there, the sources can be found, just on startup it all doesn't work...

@laeubi

laeubi commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

Now an error part is shown, not the class file editor with source.

Sorry but it seems I can not help here if you insist to show a completely different problem than is described in

I can 100% reproduce this

grafik

with the exact stacktrace that is given in the ticket

org.eclipse.ui.PartInitException: Factory org.eclipse.jdt.ui.ClassFileEditorInputFactory returned null from createElement for editor id=org.eclipse.jdt.ui.ClassFileEditor name=null
	at org.eclipse.ui.internal.EditorReference.getEditorInput(EditorReference.java:302)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPart(CompatibilityEditor.java:62)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:344)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)

as I described here (no breakpoints, just 100% reproducible just from top of master or any SDK download) and what is also exactly what @mehmet-karaman can reproduce here.

And that is what this issue fixed. So I let it decide to you (or JDT or whomever) how to proceed here, but it really becomes hilarious:

  • @iloveeclipse is complaining to see "Classfile not on classpath" what is fixed here If there is no source show the raw class file content #2357
  • @mehmet-karama is then complaining he sees null pointer problem that is fixed in this PR
  • All PRs are green but because each of you seem to use different ways, and want to solve different problems nothing happens since four days.

so instead of just merging both (as any of those is at least reproducible by one of you and go on with fixing other issues (e.g. no source is currently shows what is fixed here, one better continues to complain that I should fix "THE Problem".

For me this only shows that obviously this is n_ot a problem as all or completely unimportant_, if not even small improvements can be completed so I just wasted my time to analyze and trying to improve something here.

@iloveeclipse

Copy link
Copy Markdown
Member

but it really becomes hilarious

Instead of being that emotional, please try to understand my issue: I can reproduce the problem, I can see that none of the PR's is fixing this problem (except original trio created by Mehmet), and I know that the problem is there and real. So if you can't reproduce the problem, you probably should ask "why can't I reproduce it"?

so instead of just merging both

I do not work in the model of "just merging" something, especially if I can see that the problem is not solved.

one better continues to complain that I should fix "THE Problem".

I can't understand why you don't want to accept the fact that other people also might have right. I do not complain, I simply state the fact that I can observe and reproduce a bug and the bug needs a fix and I don't see the fix in this PR. Nothing else.

After the eclipse-pde/eclipse.pde#1667 we have regression in JDT UI. This regression can be reproduced with steps here: #2353 (comment). All what I want is a PR that fixes that. So far the fix was originally provided by @mehmet-karaman, but you was not agreed with that fix and started to create different PR's. This is right way to go, thanks for your efforts. I was asked to review these PR's and I did spend my time doing that, so far without success. This is how usual review goes. One checks the problem steps, checks the PR, sees the problem is not solved and asks for a fix. All what I want is a PR that fixes the problem.

@laeubi

laeubi commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

So well the I assume JDT will came up with a "real" fix and is not interested in contributions in that area, but then please don't blame PDE for that.

I have created a local fix and it worked fine, except some hickups like seen here

So I decided to merge whats already working and is easy to review, but it seems easier to blame other projects than trying to agree on smaller steps of improvements.

@iloveeclipse

Copy link
Copy Markdown
Member

@laeubi, please, try to be constructive, you show so much negative energy that it really not helpful.

So well the I assume JDT will came up with a "real" fix and is not interested in contributions in that area

This is wrong assumption, for sure we want contribution, but it doesn't mean we will merge everything contributed.

I have created a local fix and it worked fine

@laeubi , please try to reproduce with steps I showed. There is currently no opened PR that would fix that. If you would provide that PR, I will review it and if it works it will be merged.

but it seems easier to blame other projects

I do not blame, a state the facts. We have a regression in JDT UI, the regression is coming from eclipse-pde/eclipse.pde#1667, it is reproducible, if I revert that PR, the problem disappears.
All what I want now is to find a solution that would work, nothing else. Mehmet provided that solution, and it was fixing the problem, but you very aggressively stated that it will never be merged in PDE. Not nice, but I don't claim PDE don't want contributions, do I? Now you started to provide patches for JDT UI, which is great, that should have been done already since the regression was found, but better later then never. The sad fact is also, none of the provided patches so far fixed the problem. So we still have a regression and still need a solution.

I don't want anything special here. Take steps to reproduce. Provide PR that fixes that. Discuss on that PR towards solution. This is the way to go.

@laeubi

laeubi commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

I have now described what this fixes and how to verify the fix here

Before the fix

Editor does not restore and only shows a generic error message
grafik

After the fix

Editor does restore and detects a problem with the classpath and displays it to the user shown to the user
grafik


I leave it to the maintainers of JDT to decide if that's something useful to fix and show the real problem instead to let the Editor itself look broken. Nothing more or less this PR fixes.

@laeubi

laeubi commented Jul 23, 2025

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants