Community
Participate
Working Groups
When these things come together: 1. A ternary expression serves as method argument. 2. The condition or the alternatives of that ternary operator reference one or more explicitly final static or not static fields or explicitly final variables that all have their values assigned at their respective declarations. 3. All, condition and both alternatives, contain only literals or variables as those described in 2 and hence can be easily evaluated at compile time. 4. The value type of the alternatives (and of the ternary expression as a whole) is String. 5. No null appears anywhere in the ternary expression. 6. No boxing or unboxing is done anywhere in the ternary expression. 7. There is no explicit non-String cast anywhere in the ternary expression and there is no cast at all of the result of ternary expression (i.e. not even (String)). then Eclipse tells me for each field as described in 2 that it "cannot be resolved to a variable" and for each method local variable that it "cannot be resolved or is not a field", although the Compiler from OpenJDK 11 successfully compiles the code. (I suppose there are more aspects and details) Here is a minimalistic example class: public class C { final String s1 = ""; public void m(Object s) { final boolean b = false; final String s2 = ""; m(b? s1 : s2); } } b cannot be resolved or is not a field s1 cannot be resolved to a variable s2 cannot be resolved or is not a field "About Eclipse IDE" says: Eclipse IDE for Java Developers (includes Incubating components) Version: 2020-12 RC1 (4.18.0 RC1) Build id: 20201203-2138 (This is Linux with OpenJDK 11.)
Thanks, I can confirm on master. This is a regression in 4.18, it compiles fine in 4.17.
Works in I20200916-1800, broken in I20200920-1800, so bug 566332 is our friend. Reverting commit 0757e29b4d81fa91ed32b517ff2e5b8787913848 fixes the compilation. Jay, could you please check?
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/173585
(In reply to Eclipse Genie from comment #3) > New Gerrit change created: > https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/173585 This patch undoes what bug 566332 changed and introduces one small yet significant change. ConditionalExpression.isPolyExpression() returns false by default instead of true. I haven't gone through all the relevant spec, but if all tests run fine it is convincing enough for me.
Upgraded to 2012-02 RC2 as I figured 2012-02 would be stable by now, but hit this in our code base. It occurred where someone had this kind of declaration: private static final boolean DISABLED = false; (And then modified a logged String based upon that.)
Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/173585 was merged to [master]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=969dd97a97297dd985f4c924014f0537a709fc52
(In reply to Luke Usherwood from comment #5) > Upgraded to 2012-02 RC2 as I figured 2012-02 would be stable by now, but hit > this in our code base. It occurred where someone had this kind of > declaration: > > private static final boolean DISABLED = false; > > (And then modified a logged String based upon that.) I am not sure if this is related. Can you post a small testcase for us to try?
Sure, I'd narrowed it down to the following minimal code before finding this bugzilla (with a very similar example): public class Snippet { private static final boolean DISABLED = false; public static void main(String[] args) { print(DISABLED ? "Y" : "N"); } static void print(String s) { } } The original code went something like: if (something || DISABLED) { LOGGER.info("blah {} blah", DISABLED ? "Y" : "N");
*** Bug 569758 has been marked as a duplicate of this bug. ***
*** Bug 569797 has been marked as a duplicate of this bug. ***
Will there be a patch release with the fix for this bug? I can't compile my codebase at work because of it.
*** Bug 569824 has been marked as a duplicate of this bug. ***
*** Bug 569877 has been marked as a duplicate of this bug. ***
(In reply to Daniel Segall from comment #11) > Will there be a patch release with the fix for this bug? I can't compile my > codebase at work because of it. I second that. The codebase at our work contains too much code to refactor it in a style that compiles. This is refinately worth a hotfix release of eclipse. If you need Java 15, going down to 2020-09 isn't an option either because the plugin for Java 15 support is not available any longer: https://www.eclipse.org/forums/index.php?t=msg&th=1106384&goto=1836201&#msg_1836201
(In reply to Daniel Segall from comment #11) > Will there be a patch release with the fix for this bug? I can't compile my > codebase at work because of it. Unfortunately not, except some company decides to spent some money (== time) to maintain and produce maintenance releases. Everyone can do this, it is just matter of available resources. We will have the next release in few months. You can help to prevent such bad regressions in the future by using milestones, M1 is in January.
*** Bug 569920 has been marked as a duplicate of this bug. ***
In case it helps others who need to stick with Eclipse 2020-12, the trivial workaround is to extract the ternary expression to a local variable: From: m(b? s1 : s2); To: String s = b ? s1 : s2; m(s); Tip: the keyboard accelerators Alt+Shift+(Up,L) to help select the ternary + extract to local make very short work of this.
*** Bug 569941 has been marked as a duplicate of this bug. ***
(In reply to Luke Usherwood from comment #8) > Sure, I'd narrowed it down to the following minimal code before finding this > bugzilla (with a very similar example): > > public class Snippet { > private static final boolean DISABLED = false; > public static void main(String[] args) { > print(DISABLED ? "Y" : "N"); > } > static void print(String s) { } > } So, this issue is same as comment #0 and is fixed by this bug. If that's not the case, please let me know.
*** Bug 570089 has been marked as a duplicate of this bug. ***
Verified for Eclipse Version: 2021-03 (4.19) M1 with Build id: I20210106-1800
*** Bug 570175 has been marked as a duplicate of this bug. ***
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/174572
(In reply to Eclipse Genie from comment #23) > New Gerrit change created: > https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/174572 This is a backport to R4_18_maintenance just in case someone is interested in.
(In reply to Jayaprakash Arthanareeswaran from comment #24) > (In reply to Eclipse Genie from comment #23) > > New Gerrit change created: > > https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/174572 > > This is a backport to R4_18_maintenance just in case someone is interested > in. Cool, but there is still no hotfix release?
Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/174572 was merged to [R4_18_maintenance]. Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=1f0d2c5ae30896854ae9635225c8cb756863e24f
(In reply to Tobias Weimer from comment #25) > Cool, but there is still no hotfix release? Not with just this fix. However, you can pick up the 4.19 M1 milestone update from here: https://download.eclipse.org/eclipse/updates/4.19milestones/S-4.19M1-202101061800/
*** Bug 570848 has been marked as a duplicate of this bug. ***
*** Bug 571837 has been marked as a duplicate of this bug. ***