Ah, yes. It seems the javadocs are wrong :( They pre-date the introduction of the helper class
A better (i.e. working!) example is at https://logging.apache.org/log4j/2.x/manual/thread-context.html @Test public void name() throws Exception { try (final CloseableThreadContext.Instance ctc = CloseableThreadContext.put("key", "value")) { } } On 20 June 2016 at 14:57, Matt Sicker <[email protected]> wrote: > I tried doing it like in the javadocs and get a compilation error: > > @Test > public void name() throws Exception { > try (CloseableThreadContext.put("key", "value")) { > } > } > > List of errors: > > RequestIdFilterTest.java:12: error: <identifier> expected > try (CloseableThreadContext.put("key", "value")) { > ^ > RequestIdFilterTest.java:12: error: ')' expected > try (CloseableThreadContext.put("key", "value")) { > ^ > RequestIdFilterTest.java:12: error: '{' expected > try (CloseableThreadContext.put("key", "value")) { > ^ > RequestIdFilterTest.java:12: error: not a statement > try (CloseableThreadContext.put("key", "value")) { > ^ > RequestIdFilterTest.java:12: error: ';' expected > try (CloseableThreadContext.put("key", "value")) { > ^ > RequestIdFilterTest.java:17: error: reached end of file while parsing > } > ^ > > Am I doing something wrong here? > > -- > Matt Sicker <[email protected]> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
