-
Notifications
You must be signed in to change notification settings - Fork 139
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
StringConcatFactory can not be resolved #1842
Comments
When I change the project settings to use Java 17 for example the problem vanishes, compiling with maven/tycho that also uses ecj works without a problem... |
I saw this error today playing with one old 1.8 based plugin project containing e4 views that use old injection & annotation libs. Once switched to 17 & updating to jakarta namespace the error went away too. |
It might work with any Java 9+ as it is since 9 here: could it bee that if a dependency is using higher / more recent compile code it becomes an issue? |
There is some class file that has been compiled at a level >=9 - if you use + to concatenate strings, the dependency to |
How could that be if I have java 1.8 in project settings and clean the project? |
One of the project dependencies is compiled with Java 9+? |
That's what I suspect but the error is really odd/not very helpful and does that mean that one can no longer build code in the IDE for java 1.8 target if one of its dependencies are Java 9+? then I think a specific error message should be emitted mention the offending dependency. |
How would you run the code on the 1.8 JRE - the class file version would be to big. Is the solution to compile against a JRE 9+ but use the --release flag? |
I can compile (with Tycho!) without a problem, just the IDE shows these strange "indirectly referenced from required .class files" ... An yes it uses the |
I'm having this same issue. For years I had zero issues with Luna and finally upgraded. Now, I import a project from GitHub that I could import before, and I get this. A showstopper. I guess I'm going to give up on upgrading Eclipse. |
Have you tried the suggestion from @szarnekow to use --release in the IDE? At the moment, I can't think of another solution to this. |
If you are referring to this checkbox, then yes, it was checked. I think it has always been checked in my case. |
I can confirm the errors go away after rolling back from 2024-03 to 2023-12. |
I am having the same problem using vscode-java from 1.31.0 (May 30th, 2024). Edit: turned out my case is not caused by jdt (alone) but rather a misconfiguration in vscode-java, i.e. it does not seem to be caused by jdt but I will nevertheless leave this info here just in case someone else ends up here. It took me a while to find out how to configure and how to make it stable (survive restarts).
Setting either of these two alone does not solve the problem. Setting JDK Runtime in step 2 solves the problem only for the current session, the setting is lost during restart of VSCode. This probably deserves a ticket to vscode-java extension. |
@jarthana Are you able to reconstruct one or more scenarios where the problem can be observed so we can study options available for us ? |
Reading through the bug again it seems to me that the problem is the projects using So not sure if that is really compiler issue at all as the compiler just does what it was told by user. |
So the user told the compiler to use No one complained about the code producing any runtime problems, just the IDE shows strange errors... If its compiled with Java 21 it should be able to resolve |
I believe it would be very handy to have at least one simple reproducer everyone can look at. |
Indeed. The symptom is common and looking at Christoph's scenario, it appears this has nothing to do with StringConcatFactory, or we are dealing with two different issues. It will be good to have the bug extracted into a small workspace or project. |
It seems you already have a reproducer:
So maybe this can be shared? |
It's actually quite easy to reproduce given the discussion above: This shows a situation where this exact error message is actually justified. There may be situations where we can avoid touching the sore spot (see #543), but it cannot be eliminated completely. |
Nice, finally we see effect of #327. @chrisrueger , does this help to trace the causality?
|
@stephan-herrmann thanks for the .zip reproducer: When I import this in my (old) Eclipse 2023-12 (!) (this is the Eclipse still working) then I see this: This appears right after import the "Existing projects into Workspace".
When I change default JRE to JDK17 the error changes to:
Now I try the same with eclipse-SDK-I20240529-1800: Default JRE JDK21: Default JRE JDK17: I notice that this is different than on Eclipse 2023-12, because I do not see the errror "The type java.lang.invoke.StringConcatFactory cannot be resolved. It is indirectly referenced from required type " BUT: When I then manually change the Execution Environment to JDK 1.8. then the 2 errors are back:
Both happens regardless if Eclipse Preferences Default JRE is still on JDK 17 , JDK 21, JDK 1.8).
We have a and and I don't know how to answer the "why" other than: "because that's what our application does since ten years :)" |
Thanks, so looking for the missing class is not completely unfounded. The remaining, interesting question is: is type The fact that you have the dependency (regarding Seeing this field:
actually indicates that the author assumed that subclasses have type |
Found a solution BundleA:
Then Now I went back to the old Eclipse 2023-12 and checked how the Bnd bundle path was indeed not showing the My personal conclusion:It seems newer Eclipse >= 2024-03 is "stricter" and you need to add bundles to your -buildpath in bnd.bnd which maybe required indirectly e.g. by classes you are inheriting from (like protected members of 3rd pary classes which you are subclassing in your code, although your code does not use the inherited member directly). This was not needed before in Eclipse <= 2023-12 Mentioning @pkriens of bndtools to make him aware. Not sure if there is anything bndtools needs to do based on this observation. Update: The discussion starts with the error:
vs. in my case I got:
Notice the |
lots of things in a compiler are "demand-driven", such that small implementation changes can cause differences in which class files are needed during analysis. I don't think any specification exists, which defines a boundary between classes visible to the compiler and classes that it must not touch (although at runtime they need to be present). A decent module system might actually report some of these situations as API-leaks: accessibility of members with inaccesible type. In the end it's always a matter of "best-effort" trying to cope with missing classes based on some judgement that their absence will not affect the compilation outcome.
The variant with So at face value both are reporting the same problem, but yes, the more general "from required .class files" indicates that perhaps the path to the missing type was more obscure. |
Thanks for the explanation. It wasn't my intent to negatively criticize this. I was just surprised. and often when something stops working as before, the initial reflex is to think this is a bug :) But now that I know, I can react and solve our problem. One question out of curiosity: |
I cannot say about the original decision, which happened before Eclipse became open source :) What I can say is that this problem is classified as a build path problem. And generally all build path errors should be resolved before all other problems. Build path problems can be the root of various errors, so reporting with lesser severity would make people try to solve secondary problems before they even see the report of the (assumed) root cause. |
OK thanks. Just want to say: My problem is solved. Not sure if this is the case for the initial report by @laeubi |
I think my problem is actually different, as far as I understood the discussion here your code "suddenly" required (indirectly) a user type, this always has been the case and as far as I know bnd tools even has a Quickfix for that (PDE should now as well for Automatic Manifest projects). So even if the error message is similar the cause is different here as JDT complains about something from I see some options to really resolve this:
Also it should be investigated if something in the compiler is using |
why do you say optimization?
ignoring an error and hoping for something doesn't sound like a strategy suitable for a compiler, if you ask me.
from a compiler p.o.v. I don't see reason why this particular class should get special treatment. As we know that this error message can be caused by a wide range of possible situations, I'd love to analyse your specific problem using a minimal reproducer. Until we have a reproducer I'll focus on #543 instead. |
Oracle/Java/JDK says that
So obviously there is (a less efficient) alternative or something else that was used before Java 9+
Again the javadoc gives some hint:
So I (as a user) can't influence what the compiler emits here as I don't use this type anywhere in my code, it is more like a special byte-code instruction / built in, so I would expect it to only be used when the compiler is sure it can be used (Java >= 9) in contrast when I reference a Type in my sourceode where the compiler must use that. That's why I think special treatment would be justified here as it is more a "language feature (Java doc says |
Thanks, @laeubi now I see where you are coming from. You seem to say that the compiler chose an optimization strategy in a configuration where the class required for that strategy is not available. That's not, however, how I read the error. Saying "indirectly referenced from required .class files" seems to indicate the following two-step scenario:
It's this "something" we need to know in order to investigate, in order to see whether or not
|
Thanks for the additional explanation @stephan-herrmann
As it is a very special java class, one might think about that if the compiler find
|
Should we focus on addressing the special symptom regarding StringConcatFactory, or on finding the root cause that also affects many other situations? I very much prefer solving root causes than introducing kludges for specific situations (without having understood their root cause). Thinking of better diagnostics is of course a useful approach, that's what we did in #327 already, and I'm surprised that your issue is not helped, i.e., in your case we are unable to provide the additional information. So here's a proposal: we could introduce a "hidden" flag via a system property that will let the compiler print more debug information (mostly: stacktrace) to console when the problem occurs. Will you be able to reproduce the problem with a compiler from a PR or I-Build and report back any stacktraces that will be printed with that flag enabled? Otherwise I would wait what happens first:
|
The situation is that one see the error when the project uses Java 1.8 and goes away once one uses a higher Java version, so I'm not sure what else should be the root cause than that Java 1.8 does not has |
Let's call this the surface cause. What we need is understanding why the compiler considers
|
I don't see anything we can reasonably do here. Closing. |
The fix for me was to change the default-JRE tick from 1.8 to 22 in Preferences->Java->Installed JREs. No change to a project's JRE and compatibility would substitute and remove these could-not-build errors. |
Today I got a quite strange error in the IDE
but I never use that anywhere in my code.
The only "special" think seems be that my code is using java 1.8 JVM, I already cleaned the project but the project still persist.
The text was updated successfully, but these errors were encountered: