ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 60767] New: NPE during unit testing of GenerateKey.DistinguishedName class
Date Wed, 22 Feb 2017 16:06:05 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=60767

            Bug ID: 60767
           Summary: NPE during unit testing of
                    GenerateKey.DistinguishedName class
           Product: Ant
           Version: nightly
          Hardware: Macintosh
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Core tasks
          Assignee: notifications@ant.apache.org
          Reporter: mjkim0324@hotmail.com
  Target Milestone: ---

I get an NPE during unit testing of GenerateKey.DistinguishedName class. 

public void test() throws Throwable {
  DistinguishedName name = new DistinguishedName();
  name.createParam();
  name.toString();
}

Call Stack
org.apache.tools.ant.taskdefs.GenerateKey$DistinguishedName.encode(GenerateKey.java:138)
org.apache.tools.ant.taskdefs.GenerateKey$DistinguishedName.toString(GenerateKey.java:122)
test()


public String toString() {
  final int size = params.size();
  final StringBuffer sb = new StringBuffer();
  boolean firstPass = true;

  for (int i = 0; i < size; i++) {
    if (!firstPass) {
      sb.append(" ,");
    }
    firstPass = false;

    final DnameParam param = (DnameParam) params.elementAt(i);
    sb.append(encode(param.getName())); // line 122 
    sb.append('=');
    sb.append(encode(param.getValue()));
  }

  return sb.toString();
}

public String encode(final String string) {
  int end = string.indexOf(','); // line 138 - NPE because string is null
  ...
}


At line 138, NPE occurs because DnameParam object (param) created in
createParam() does not set its fields properly. So, param.getName() in
toString() returns null and passed as an argument of encode(...).
To avoid a crash, I think either createParam() should set its fields with
default values at least, or a null-checker should be added in toString or
encode methods.

-- 
You are receiving this mail because:
You are the assignee for the bug.
Mime
View raw message