Return-Path: X-Original-To: apmail-logging-log4j-dev-archive@www.apache.org Delivered-To: apmail-logging-log4j-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EE44A11E99 for ; Mon, 7 Jul 2014 15:35:54 +0000 (UTC) Received: (qmail 65386 invoked by uid 500); 7 Jul 2014 15:35:54 -0000 Delivered-To: apmail-logging-log4j-dev-archive@logging.apache.org Received: (qmail 65332 invoked by uid 500); 7 Jul 2014 15:35:54 -0000 Mailing-List: contact log4j-dev-help@logging.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Log4J Developers List" Reply-To: "Log4J Developers List" Delivered-To: mailing list log4j-dev@logging.apache.org Received: (qmail 65319 invoked by uid 99); 7 Jul 2014 15:35:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jul 2014 15:35:54 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of garydgregory@gmail.com designates 209.85.220.46 as permitted sender) Received: from [209.85.220.46] (HELO mail-pa0-f46.google.com) (209.85.220.46) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Jul 2014 15:35:50 +0000 Received: by mail-pa0-f46.google.com with SMTP id eu11so5655544pac.33 for ; Mon, 07 Jul 2014 08:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=kKPaDIFb3IGlJiplGjb9shJwSs5Jf9wY2xokSTCQ6og=; b=nYIG/RtFm94t5Nod0Bx/SQPTsazXAD71zPw2uMKhvGu+JvCxohFcZrgzpNOByVpbP9 Je6sxIKjw0SFh4sSia2OYsW9j8zk/asXVvbyrZFvpbtYYabZYQG0tgznjd/0vrON+YK1 12lSOgAeXjaCL/JU9ei4MsUbwo2BiBbfwUjwehOQ/8/oQLlcbHrgEe5ej9Jg2MxCyGAS Ow4DgC5/X7LtiurOotS20h3E2KvIvEtilFZgeMjoO8zDTT6d4eTVBc/H+pmfgoqTnBW7 i6DKxfvigN3L+5HoSo1ntTqPwI9OZrFzMgS9AEp0l8EPQRKaEs3y/3UEZitkmyrbvNjE R9Kg== MIME-Version: 1.0 X-Received: by 10.70.89.77 with SMTP id bm13mr29074251pdb.51.1404747330231; Mon, 07 Jul 2014 08:35:30 -0700 (PDT) Received: by 10.70.67.35 with HTTP; Mon, 7 Jul 2014 08:35:30 -0700 (PDT) Date: Mon, 7 Jul 2014 11:35:30 -0400 Message-ID: Subject: org.apache.logging.log4j.core.config.plugins.PluginAttribute.required() From: Gary Gregory To: Log4J Developers List Content-Type: multipart/alternative; boundary=001a11c21fda9e24ac04fd9c3912 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c21fda9e24ac04fd9c3912 Content-Type: text/plain; charset=UTF-8 Why don't we have a required flag? Using it and throwing an Exception when this condition is violated would avoid guard code like: @PluginFactory public static RegexFilter createFilter( @PluginAttribute("regex") final Pattern regex, @PluginAttribute("useRawMsg") final Boolean useRawMsg, @PluginAttribute("onMatch") final Result match, @PluginAttribute("onMismatch") final Result mismatch) { if (regex == null) { LOGGER.error("A regular expression must be provided for RegexFilter"); return null; } return new RegexFilter(useRawMsg, regex, match, mismatch); } ? -- E-Mail: garydgregory@gmail.com | ggregory@apache.org Java Persistence with Hibernate, Second Edition JUnit in Action, Second Edition Spring Batch in Action Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory --001a11c21fda9e24ac04fd9c3912 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Why don't we have a required flag?

U= sing it and throwing an Exception when this condition is violated would avo= id guard code like:

=C2=A0=C2=A0=C2=A0 @PluginFactory
=C2=A0=C2= =A0=C2=A0 public static RegexFilter createFilter(
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 @PluginA= ttribute("regex") final Pattern regex,
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 @PluginAttribute("useRaw= Msg") final Boolean useRawMsg,
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 @PluginAttribute("onMatch") final = Result match,
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 @PluginA= ttribute("onMismatch") final Result mismatch) {

=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (regex =3D=3D null) {
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 LOGGER.error("A= regular expression must be provided for RegexFilter");
=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return null;
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }
=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 return new RegexFilter(useRawMsg, regex, match, mismatch);<= br>=C2=A0=C2=A0=C2=A0 }

?
--001a11c21fda9e24ac04fd9c3912--