From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20430 invoked by alias); 20 Mar 2008 18:06:02 -0000 Received: (qmail 20420 invoked by uid 22791); 20 Mar 2008 18:06:02 -0000 X-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_36,J_CHICKENPOX_64,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 20 Mar 2008 18:05:44 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m2KI5gUA025541 for ; Thu, 20 Mar 2008 14:05:42 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m2KI5gKf007970; Thu, 20 Mar 2008 14:05:42 -0400 Received: from opsy.redhat.com (vpn-248-24.boston.redhat.com [10.13.248.24]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m2KI5fes002347; Thu, 20 Mar 2008 14:05:41 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id B7C3350818E; Thu, 20 Mar 2008 11:11:32 -0600 (MDT) To: Andrew Cagney Cc: Phil Muldoon , Frysk Hackers Subject: Re: Patch: Add Option Groups References: <47DFFE9D.80906@redhat.com> <47E021DF.40407@redhat.com> <47E0C4DC.2080609@redhat.com> <47E24FB8.7090507@redhat.com> <47E28BF9.5020400@redhat.com> From: Tom Tromey Reply-To: Tom Tromey X-Attribution: Tom Date: Thu, 20 Mar 2008 18:06:00 -0000 In-Reply-To: <47E28BF9.5020400@redhat.com> (Andrew Cagney's message of "Thu\, 20 Mar 2008 12\:08\:25 -0400") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2008-q1/txt/msg00178.txt.bz2 >>>>> "Andrew" == Andrew Cagney writes: [ Parser and OptionGroup ] Andrew> I'm not sure if its an interface restriction, or a bug; either way it Andrew> leads to a confusing client problem. I checked in a fix to the Classpath repository. I've appended it as well. Tom ChangeLog: 2008-03-20 Tom Tromey * tools/gnu/classpath/tools/getopt/Parser.java (options): Don't initialize. (add, addFinal): Don't update options. (requireOptions): New method. (printHelp): Synchronize. Call requireOptions. (parse): Call requireOptions. Index: tools/gnu/classpath/tools/getopt/Parser.java =================================================================== RCS file: /cvsroot/classpath/classpath/tools/gnu/classpath/tools/getopt/Parser.java,v retrieving revision 1.9 diff -u -r1.9 Parser.java --- tools/gnu/classpath/tools/getopt/Parser.java 22 Sep 2006 01:01:26 -0000 1.9 +++ tools/gnu/classpath/tools/getopt/Parser.java 20 Mar 2008 18:02:58 -0000 @@ -1,5 +1,5 @@ /* Parser.java - parse command line options - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2008 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -66,7 +66,9 @@ private boolean longOnly; - private ArrayList options = new ArrayList(); + // All of the options. This is null initially; users must call + // requireOptions before access. + private ArrayList options; private ArrayList optionGroups = new ArrayList(); @@ -218,7 +220,6 @@ */ public synchronized void add(Option opt) { - options.add(opt); defaultGroup.add(opt); } @@ -230,7 +231,6 @@ */ protected synchronized void addFinal(Option opt) { - options.add(opt); finalGroup.add(opt); } @@ -242,7 +242,6 @@ */ public synchronized void add(OptionGroup group) { - options.addAll(group.options); // This ensures that the final group always appears at the end // of the options. if (optionGroups.isEmpty()) @@ -251,13 +250,29 @@ optionGroups.add(optionGroups.size() - 1, group); } + // Make sure the 'options' field is properly initialized. + private void requireOptions() + { + if (options != null) + return; + options = new ArrayList(); + Iterator it = optionGroups.iterator(); + while (it.hasNext()) + { + OptionGroup group = (OptionGroup) it.next(); + options.addAll(group.options); + } + } + public void printHelp() { this.printHelp(System.out); } - void printHelp(PrintStream out) + synchronized void printHelp(PrintStream out) { + requireOptions(); + if (headerText != null) { formatText(out, headerText); @@ -417,6 +432,7 @@ */ public synchronized void parse(String[] inArgs, FileArgumentCallback files) { + requireOptions(); try { args = inArgs;