I thought we were going to Java 7 for 2.0?

Gary

-------- Original message --------
From: Damjan Jovanovic <dam...@apache.org> 
Date:11/04/2013  02:11  (GMT-05:00) 
To: Commons Developers List <dev@commons.apache.org> 
Subject: Re: Backporting try-with-resources to Java < 7 (was: Re: [imaging] 
Closing stream) 

For the record, I would only use this for imaging >= 2.0.

Weaver looked undocumented and undecipherable to me, but let me look at it
again slowly.

Damjan


On Sun, Nov 3, 2013 at 9:14 PM, Matt Benson <gudnabr...@gmail.com> wrote:

> I wasn't under the impression this was blocking imaging 1.0. In any case,
> framing Damjan's work as a Weaver module would still use the same work he's
> done with ASM and would really only utilize a standard mechanism for
> triggering the process. It would also avoid proliferation of multiple maven
> plugins with essentially the same mission: post-processing bytecode.
>
> Matt
> On Nov 3, 2013 10:08 AM, "Gary Gregory" <garydgreg...@gmail.com> wrote:
>
> > On Sun, Nov 3, 2013 at 10:56 AM, Matt Benson <gudnabr...@gmail.com>
> wrote:
> >
> >> Sounds like it would be trivial to frame what you've done here into the
> >> context of a Weaver module, for which there exist both a maven plugin
> and
> >> an Antlib, as well as a need for a near-term release. :-)
> >>
> >
> > and eating our own dog food :)
> >
> > We may pushing the limits of Dajman's patience for a 1.0 which is long
> > overdue.
> >
> > I suppose D needs to weigh using ASM or [weaver] vs. adjusting the
> current
> > code with Java 5.
> >
> > Gary
> >
> >>
> >> Matt
> >> On Nov 3, 2013 2:30 AM, "Damjan Jovanovic" <dam...@apache.org> wrote:
> >>
> >> > On Fri, Oct 25, 2013 at 1:52 PM, Matt Benson <gudnabr...@gmail.com>
> >> wrote:
> >> >
> >> > > On Oct 25, 2013 6:30 AM, "Damjan Jovanovic" <damjan....@gmail.com>
> >> > wrote:
> >> > > >
> >> > > > On Fri, Oct 25, 2013 at 12:36 PM, Jörg Schaible
> >> > > > <joerg.schai...@scalaris.com> wrote:
> >> > > > > Hi Damjan,
> >> > > > >
> >> > > > > Damjan Jovanovic wrote:
> >> > > > >
> >> > > > > [snip]
> >> > > > >
> >> > > > > Thanks for explanation.
> >> > > > >
> >> > > > >> We would be able to adapt that for Java < 1.7 by swallowing the
> >> > close
> >> > > > >> exception instead of calling addSuppressed() on the primary
> >> > exception,
> >> > > > >> but the show stopper is catching and rethrowing the primary
> >> > exception
> >> > > > >> (Throwable), which javac < 1.7 refuses to compile because it
> >> doesn't
> >> > > > >> do "Rethrowing Exceptions with More Inclusive Type Checking"
> >> > > > >> (
> >> > >
> >> > >
> >> >
> >>
> http://docs.oracle.com/javase/7/docs/technotes/guides/language/catch-multiple.html
> >> > > ).
> >> > > > >>
> >> > > > >> But this would work and always sets succeeded correctly without
> >> > > > >> catch/re-throw:
> >> > > > >>
> >> > > > >> final InputStream is = factoryMethodThatCanThrow();
> >> > > > >> boolean succeeded = false;
> >> > > > >> try {
> >> > > > >>     try {
> >> > > > >>         is.methodThatCanThrow();
> >> > > > >>     } finally {
> >> > > > >>     }
> >> > > > >>     succeeded = true;
> >> > > > >> } finally {
> >> > > > >>     closeSafely(!succeeded, is);
> >> > > > >> }
> >> > > > >
> >> > > > > I guess the nested try was unintentionally ;-)
> >> > > > >
> >> > > > > Cheers,
> >> > > > > Jörg
> >> > > >
> >> > > > Well that actually won't work, because the "succeeded = true;"
> will
> >> be
> >> > > > skipped if there is a "return;" in the inner try.
> >> > > >
> >> > > > Other than a custom Java compiler, I guess there's no clean way of
> >> > > > doing this in Java < 1.7. There's really only option 2 - with
> being
> >> > > > careful to always set succeeded correctly on all paths out of the
> >> try
> >> > > > block. Almost like releasing memory in C.
> >> > > >
> >> > >
> >> > > I haven't deeply followed this conversation, but would this be a
> >> > candidate
> >> > > for a [weaver] module?
> >> > >
> >> > > Matt
> >> > >
> >> > >
> >> >
> >> > [weaver] I am less sure about, but by playing with Objectweb's ASM I
> did
> >> > manage to compile code with try-with-resources on Java 7, change the
> >> class
> >> > file version, do some bytecode manipulation to delete calls to
> >> > Throwable.addSuppressed(), and get it to work on Java < 7.
> >> >
> >> > Made it into a Maven plugin and it works well :). Also verified other
> >> Java
> >> > 7 language features (binary literals, underscores in numeric literals,
> >> > strings in switch, diamonds, exception multi-catch and re-throw) work
> on
> >> > Java < 7 because they're just syntactic sugar.
> >> >
> >> > It's very small and simple - 143 lines in 1 file. Is it worth adding
> as
> >> a
> >> > new commons project? Or do we not host (projects that contain) Maven
> >> > plugins?
> >> >
> >> > Damjan
> >> >
> >>
> >
> >
> >
> > --
> > E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
> > Java Persistence with Hibernate, Second Edition<
> http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
>

Reply via email to