I am wondering if anyone can help me.

I have an issue with compiling some code in Eclipse but not with IntelliJ or javac.

I am using sneakyThrow to bubble a checked exception up through 2 streams.

Here is the smallest reproducible code I can make:

import java.io.IOException;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Example {
	public static void main(String[] args)
	throws IOException {
		List<List<Integer>> input = List.of(List.of(1, 2), List.of(2, 4));

		// Should return any List whose elements are all even.
		List<List<Integer>> output = input.stream()
			.filter(bubblePredicate(o -> o.stream()
				.allMatch(bubblePredicate(i -> {
					if (i > 10) {
						throw new IOException("Number too large.");
					}
					return i % 2 == 0;
				}))))
			.collect(Collectors.toList());

		System.out.println(output);
	}

	private interface ThrowingPredicate<S, E extends Exception> {
		boolean test(S s) throws E;
	}

	private static <S, E extends Exception> Predicate<S> bubblePredicate(ThrowingPredicate<S, E> callable)
	throws E {
		return s -> {
			try {
				return callable.test(s);
			}
			catch (Exception e) {
				sneakyThrow(e);
				return false;
			}
		};
	}

	private static <E extends Throwable> void sneakyThrow(Exception exception)
	throws E {
		throw (E)exception;
	}
}

Compiles and runs completely fine with javac 11.0.12, but doesn’t on Eclipse 4.21.0.I20210906-0500 nor Eclipse 4.27.0.20230309-1200.

Has anyone encountered this before, or have any idea what I am misunderstanding?

  • HamsterRage@lemmy.ca
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    “Doesn’t work”, is a fairly useless description of the problem. Does it cause your computer to reboot? Does it spout haiku at you? Are you getting some kind of feedback that might indicate the nature of the problem? If so, you should share it, too.

    • ThreenOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      1 year ago

      Yeah mate, you are right “doesn’t work” is pretty useless, lucky I didn’t say that

      I said I have code that does compile in one specific compiler but doesn’t in another specific one, and asked if anyone had ever encountered that before

      And 2 days ago when someone mentioned that I didn’t include the actual error, I apologised and then included it

      • HamsterRage@lemmy.ca
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        I’m not going argue semantics with you - but you’re making it harder to get help if you don’t explain what “doesn’t compile” means?

        • ThreenOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 year ago

          I am really struggling to understand what you are asking me to provide

          Java is a compiled language. Eclipse is attempting that compile step and it fails. I have provided the error it gives me, a minimal code snippet to reproduce this, the location that Eclipse indicate the error occurs, and the specific 2 specific versions of Eclipse I have tried

          Is it a screenshot of the error you are after? Maybe there is something obvious I am overlooking, but I really do no know what more I can give you

          • HamsterRage@lemmy.ca
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 year ago

            Something is going on here. I don’t see anyone else’s comments, nor do I see the error message.

              • HamsterRage@lemmy.ca
                link
                fedilink
                English
                arrow-up
                2
                ·
                1 year ago

                Well it explains why I looked so much like jerk (partially, at least). I’m still confused about why this is happening.

                I see the comments in your screen snap, but I still don’t see them in the app. I’m going look if I see them in a browser.

                Maybe this is a federating issue???

                • ThreenOP
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  1 year ago

                  Haha, sorry I came across the way I did. I really was racking my brain trying to think what more I could provide. Normally for Java issues I can give a stacktrace, but in this case there is literally only a 4-word error message

                  When I view the post on your server it shows only our convo, so definitely a federation issue