commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Biesack (JIRA)" <>
Subject [jira] Created: (CLI-144) adding a FileValidator results in ClassCastException in parser.parseAndHelp(args)
Date Fri, 17 Aug 2007 15:28:30 GMT
adding a FileValidator results in ClassCastException in parser.parseAndHelp(args)

                 Key: CLI-144
             Project: Commons CLI
          Issue Type: Bug
          Components: CLI-2.x
    Affects Versions: 2.0
         Environment: Windows XP
            Reporter: David Biesack

When I add a FileValidator.getExistingFileInstance() to an Argument, I get a ClassCastException
when I parse args.

Below is a testcase invoke with

   java org.apache.commons.cli2.issues.CLI2Sample -classpath commons-cli-2.0-SNAPSHOT.jar
--file-name path-to-an-existing-file

Run it and you get:

Exception in thread "main" java.lang.ClassCastException: cannot be cast to java.lang.String
	at org.apache.commons.cli2.validation.FileValidator.validate(
	at org.apache.commons.cli2.option.ArgumentImpl.validate(
	at org.apache.commons.cli2.option.ParentImpl.validate(
	at org.apache.commons.cli2.option.DefaultOption.validate(
	at org.apache.commons.cli2.option.GroupImpl.validate(
	at org.apache.commons.cli2.commandline.Parser.parse(
	at org.apache.commons.cli2.commandline.Parser.parseAndHelp(
	at org.apache.commons.cli2.issues.CLI2Sample.main(

Comment out the withValidator call and it runs with no exception. 

I also get a similar ClassCastException if I add a 


to another option/argument.

package org.apache.commons.cli2.issues;

import org.apache.commons.cli2.CommandLine;
import org.apache.commons.cli2.Group;
import org.apache.commons.cli2.builder.ArgumentBuilder;
import org.apache.commons.cli2.builder.DefaultOptionBuilder;
import org.apache.commons.cli2.builder.GroupBuilder;
import org.apache.commons.cli2.commandline.Parser;
import org.apache.commons.cli2.option.DefaultOption;
import org.apache.commons.cli2.validation.FileValidator;

public class CLI2Sample
   public static void main(String[] args)
      final DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
      final ArgumentBuilder abuilder = new ArgumentBuilder();
      final GroupBuilder gbuilder = new GroupBuilder();
      DefaultOption fileNameOption = obuilder//
            .withDescription("Name of dense data file containing NxM double matrix") //
      Group options = gbuilder//
      Parser parser = new Parser();
      CommandLine cl = parser.parseAndHelp(args);

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message