Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 76BB2200B16 for ; Mon, 20 Jun 2016 16:01:45 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 7536A160A55; Mon, 20 Jun 2016 14:01:45 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BF0AB160A26 for ; Mon, 20 Jun 2016 16:01:44 +0200 (CEST) Received: (qmail 77860 invoked by uid 500); 20 Jun 2016 14:01:43 -0000 Mailing-List: contact log4j-user-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Users List" Reply-To: "Log4J Users List" Delivered-To: mailing list log4j-user@logging.apache.org Received: (qmail 77849 invoked by uid 99); 20 Jun 2016 14:01:43 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Jun 2016 14:01:43 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 49CBD18064B for ; Mon, 20 Jun 2016 14:01:43 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.821 X-Spam-Level: X-Spam-Status: No, score=-0.821 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id lzstoU_Vk_xN for ; Mon, 20 Jun 2016 14:01:42 +0000 (UTC) Received: from mail-vk0-f45.google.com (mail-vk0-f45.google.com [209.85.213.45]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id BA6F25F3F2 for ; Mon, 20 Jun 2016 14:01:41 +0000 (UTC) Received: by mail-vk0-f45.google.com with SMTP id j2so196471262vkg.2 for ; Mon, 20 Jun 2016 07:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=P3BmWMHopnw9rku3XeA+nVDNNQtnEIrGjomIla/AJQM=; b=kPY9YEIDWs0DzrAa2fqHbxnFqlHg/8SCc4YV/0BzNbBPB0095bo8BTdDq2h04TAu8F GkjefMcS2OMUS2tI6BFhUihv9B3ARbkJUcZdobdDn0LboafuqbLEPeVYZd1NbnMcapE2 M+rbxMHh31y0AzsLCjgFP5pM7mwxv3JuWW7enQovnu81WJJwOVMA+9/x2O3KGavnug1N FI0BlxcQViXTEaDmoAY8q8OtNnlT+bvgUS5i4urONqhh1CwPXqfjl5UaS0tofywu585+ p61IyIJbzpHT4lHMFNz8f/eOqGL1XnaSzmAjkfGofT/zRSUrLG4aCEgP3XYdOK0+hGR3 w91Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=P3BmWMHopnw9rku3XeA+nVDNNQtnEIrGjomIla/AJQM=; b=OylKO9NOge6r5DznmnE0GudXzn03KL7QEUBhZ2vEgN9D1pdotFQLr8bKLYgAip/MPp qdoNVjXRiX3YJtTPuxOgDm8oflWaYSviSINS1gK/8Mwd0t8PqhZr0ZIyorRoT26f3HrD hWMYmBcfwg42CivnH6e2K9rghGy02vNy1nz2cwxzs0Qulo8CEc/fZw+ZWvEScmpHRlRt 8xS7b4wAgJfZAi8j59RtzTnMumDwuNIN7uNgdicSCSAIYD7+zbVGbPnBYgvBsw777sSC Zh3MFZ+KoyW+jDIgusU95VBHPb5C7rRkMxyhl8FRa88yf8f0SbgaYpWGgaowf6G1Q7L+ enVQ== X-Gm-Message-State: ALyK8tJgxYFIXOVacadvF62II3ttdXLbki/h+Ct7n94cwd6o7AgVMGQw+5AxvquJjIFtigiZodmL4kj+zLIAkQ== X-Received: by 10.159.41.229 with SMTP id s92mr7045365uas.73.1466431300800; Mon, 20 Jun 2016 07:01:40 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.81.129 with HTTP; Mon, 20 Jun 2016 07:01:40 -0700 (PDT) In-Reply-To: References: From: Greg Thomas Date: Mon, 20 Jun 2016 15:01:40 +0100 Message-ID: Subject: Re: How exactly are you supposed to use CloseableThreadContext? To: Log4J Users List Content-Type: text/plain; charset=UTF-8 archived-at: Mon, 20 Jun 2016 14:01:45 -0000 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 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: 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 --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org For additional commands, e-mail: log4j-user-help@logging.apache.org