Giter Site home page Giter Site logo

Comments (9)

mpalat avatar mpalat commented on August 17, 2024

Thanks @SwathiKalahastri for raising this

from eclipse.jdt.core.

srikanth-sankaran avatar srikanth-sankaran commented on August 17, 2024

The segment

49: aload_2
50: aload_3
51: if_acmpeq     59

in ECJ generated code look suspect.

JLS 20 gives this translation scheme:

14.20.3.1

...

The meaning of a basic try-with-resources statement of the form:

try ({VariableModifier} R Identifier = Expression ...)
Block

is given by by the following translation to a local variable declaration and a try-catchfinally
statement:

{
    final {VariableModifierNoFinal} R Identifier = Expression;
    Throwable #primaryExc = null;
    try ResourceSpecification_tail
        Block
    catch (Throwable #t) {
        #primaryExc = #t;
        throw #t;
    } finally {
        if (Identifier != null) {
            if (#primaryExc != null) {
                try {
                    Identifier.close();
                } catch (Throwable #suppressedExc) {
                   #primaryExc.addSuppressed(#suppressedExc);
                }
            } else {
                Identifier.close();
            }
        }
    }
}

There is no provision for the comparison and jump in this scheme. I wonder if draft JLS7 wording somehow suggested this.

from eclipse.jdt.core.

srikanth-sankaran avatar srikanth-sankaran commented on August 17, 2024

PR here: #1033

from eclipse.jdt.core.

iloveeclipse avatar iloveeclipse commented on August 17, 2024

This seem to cause a massive amount of regressions in our internal (Advantest) tests.

The code that uses "try with resources" (or wrapped into such try block) now fails in many cases reporting

java.lang.IllegalArgumentException: Self-suppression not permitted at java.base/java.lang.Throwable.addSuppressed(Throwable.java:1072) at

in places where we never call Throwable.addSuppressed().

We don't see the problem with I20230504-1800 and we see it with I20230511-1800.
PR #1033 seem to be the best candidate.

I will try to create a standalone reproducer.

from eclipse.jdt.core.

iloveeclipse avatar iloveeclipse commented on August 17, 2024

I will try to create a standalone reproducer.

Turns out, it is trivial:

import java.io.Closeable;
import java.io.IOException;

public class X {
	public static void main(String[] args) throws IOException {
		try (DummyClosable closable = new DummyClosable()) {
			throw new IOException("OMG!!!");
		} catch (IOException e) {
			throw e;
		}
	}

	static class DummyClosable implements Closeable {
		@Override
		public void close() throws IOException {
			System.out.println("Closed!");
		}
	}
}

Executed with ecj from master it throws IllegalArgumentException:

Closed!
Exception in thread "main" java.lang.IllegalArgumentException: Self-suppression not permitted
	at java.base/java.lang.Throwable.addSuppressed(Throwable.java:1072)
	at X.main(X.java:8)
Caused by: java.io.IOException: OMG!!!
	at X.main(X.java:7)

With commit 2bac9e4 reverted, it prints what is expected to print:

Closed!
Exception in thread "main" java.io.IOException: OMG!!!
	at X.main(X.java:7)

@srikanth-sankaran : this must be fixed or 2bac9e4 reverted before M3 which is this Thursday.

from eclipse.jdt.core.

srikanth-sankaran avatar srikanth-sankaran commented on August 17, 2024

Thanks for the reduced test case. I will get on this right away.

from eclipse.jdt.core.

iloveeclipse avatar iloveeclipse commented on August 17, 2024

@srikanth-sankaran : anything here to do, or why this issue is still opened?

from eclipse.jdt.core.

srikanth-sankaran avatar srikanth-sankaran commented on August 17, 2024

@srikanth-sankaran : anything here to do, or why this issue is still opened?

The original problem reported by SwathiKalahastri is still there on master. My attempted solution was reverted due to a regression and I haven't had an opportunity to revisit yet.

from eclipse.jdt.core.

iloveeclipse avatar iloveeclipse commented on August 17, 2024

Ah, I remember now, I've removed 4.29 milestone now.

from eclipse.jdt.core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.