Program: 109167
Project: 109167
Buggy source:
protected void parsePath(){
  family=PATH;
  kind=0;
  String pathData=element.getString("String_Node_Str");
  if (pathData == null || PApplet.trim(pathData).length() == 0) {
    return;
  }
  char[] pathDataChars=pathData.toCharArray();
  StringBuffer pathBuffer=new StringBuffer();
  boolean lastSeparate=false;
  for (int i=0; i < pathDataChars.length; i++) {
    char c=pathDataChars[i];
    boolean separate=false;
    if (c == 'M' || c == 'm' || c == 'L' || c == 'l' || c == 'H' || c == 'h' || c == 'V' || c == 'v' || c == 'C' || c == 'c' || c == 'S' || c == 's' || c == 'Q' || c == 'q' || c == 'T' || c == 't' || c == 'Z' || c == 'z' || c == ',') {
      separate=true;
      if (i != 0) {
        pathBuffer.append("String_Node_Str");
      }
    }
    if (c == 'Z' || c == 'z') {
      separate=false;
    }
    if (c == '-' && !lastSeparate) {
      if (i == 0 || pathDataChars[i - 1] != 'e') {
        pathBuffer.append("String_Node_Str");
      }
    }
    if (c != ',') {
      pathBuffer.append(c);
    }
    if (separate && c != ',' && c != '-') {
      pathBuffer.append("String_Node_Str");
    }
    lastSeparate=separate;
  }
  String[] pathTokens=PApplet.splitTokens(pathBuffer.toString(),"String_Node_Str" + WHITESPACE);
  vertices=new float[pathTokens.length][2];
  vertexCodes=new int[pathTokens.length];
  float cx=0;
  float cy=0;
  int i=0;
  char implicitCommand='\0';
  boolean prevCurve=false;
  float ctrlX, ctrlY;
  while (i < pathTokens.length) {
    char c=pathTokens[i].charAt(0);
    if (((c >= '0' && c <= '9') || (c == '-')) && implicitCommand != '\0') {
      c=implicitCommand;
      i--;
    }
 else {
      implicitCommand=c;
    }
switch (c) {
case 'M':
      cx=PApplet.parseFloat(pathTokens[i + 1]);
    cy=PApplet.parseFloat(pathTokens[i + 2]);
  parsePathMoveto(cx,cy);
implicitCommand='L';
i+=3;
break;
case 'm':
cx=cx + PApplet.parseFloat(pathTokens[i + 1]);
cy=cy + PApplet.parseFloat(pathTokens[i + 2]);
parsePathMoveto(cx,cy);
implicitCommand='l';
i+=3;
break;
case 'L':
cx=PApplet.parseFloat(pathTokens[i + 1]);
cy=PApplet.parseFloat(pathTokens[i + 2]);
parsePathLineto(cx,cy);
i+=3;
break;
case 'l':
cx=cx + PApplet.parseFloat(pathTokens[i + 1]);
cy=cy + PApplet.parseFloat(pathTokens[i + 2]);
parsePathLineto(cx,cy);
i+=3;
break;
case 'H':
cx=PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'h':
cx=cx + PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'V':
cy=PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'v':
cy=cy + PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'C':
{
float ctrlX1=PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY1=PApplet.parseFloat(pathTokens[i + 2]);
float ctrlX2=PApplet.parseFloat(pathTokens[i + 3]);
float ctrlY2=PApplet.parseFloat(pathTokens[i + 4]);
float endX=PApplet.parseFloat(pathTokens[i + 5]);
float endY=PApplet.parseFloat(pathTokens[i + 6]);
parsePathCurveto(ctrlX1,ctrlY1,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=7;
prevCurve=true;
}
break;
case 'c':
{
float ctrlX1=cx + PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY1=cy + PApplet.parseFloat(pathTokens[i + 2]);
float ctrlX2=cx + PApplet.parseFloat(pathTokens[i + 3]);
float ctrlY2=cy + PApplet.parseFloat(pathTokens[i + 4]);
float endX=cx + PApplet.parseFloat(pathTokens[i + 5]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 6]);
parsePathCurveto(ctrlX1,ctrlY1,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=7;
prevCurve=true;
}
break;
case 'S':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float ctrlX2=PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY2=PApplet.parseFloat(pathTokens[i + 2]);
float endX=PApplet.parseFloat(pathTokens[i + 3]);
float endY=PApplet.parseFloat(pathTokens[i + 4]);
parsePathCurveto(ctrlX,ctrlY,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 's':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float ctrlX2=cx + PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY2=cy + PApplet.parseFloat(pathTokens[i + 2]);
float endX=cx + PApplet.parseFloat(pathTokens[i + 3]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 4]);
parsePathCurveto(ctrlX,ctrlY,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 'Q':
{
ctrlX=PApplet.parseFloat(pathTokens[i + 1]);
ctrlY=PApplet.parseFloat(pathTokens[i + 2]);
float endX=PApplet.parseFloat(pathTokens[i + 3]);
float endY=PApplet.parseFloat(pathTokens[i + 4]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 'q':
{
ctrlX=cx + PApplet.parseFloat(pathTokens[i + 1]);
ctrlY=cy + PApplet.parseFloat(pathTokens[i + 2]);
float endX=cx + PApplet.parseFloat(pathTokens[i + 3]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 4]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 'T':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float endX=PApplet.parseFloat(pathTokens[i + 1]);
float endY=PApplet.parseFloat(pathTokens[i + 2]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=3;
prevCurve=true;
}
break;
case 't':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float endX=cx + PApplet.parseFloat(pathTokens[i + 1]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 2]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=3;
prevCurve=true;
}
break;
case 'Z':
case 'z':
close=true;
i++;
break;
default :
String parsed=PApplet.join(PApplet.subset(pathTokens,0,i),"String_Node_Str");
String unparsed=PApplet.join(PApplet.subset(pathTokens,i),"String_Node_Str");
System.err.println("String_Node_Str" + parsed);
System.err.println("String_Node_Str" + unparsed);
if (pathTokens[i].equals("String_Node_Str") || pathTokens[i].equals("String_Node_Str")) {
String msg="String_Node_Str" + "String_Node_Str";
throw new RuntimeException(msg);
}
throw new RuntimeException("String_Node_Str" + pathTokens[i]);
}
}
}

Fixed version (ground truth):
protected void parsePath(){
  family=PATH;
  kind=0;
  String pathData=element.getString("String_Node_Str");
  if (pathData == null || PApplet.trim(pathData).length() == 0) {
    return;
  }
  char[] pathDataChars=pathData.toCharArray();
  StringBuffer pathBuffer=new StringBuffer();
  boolean lastSeparate=false;
  for (int i=0; i < pathDataChars.length; i++) {
    char c=pathDataChars[i];
    boolean separate=false;
    if (c == 'M' || c == 'm' || c == 'L' || c == 'l' || c == 'H' || c == 'h' || c == 'V' || c == 'v' || c == 'C' || c == 'c' || c == 'S' || c == 's' || c == 'Q' || c == 'q' || c == 'T' || c == 't' || c == 'Z' || c == 'z' || c == ',') {
      separate=true;
      if (i != 0) {
        pathBuffer.append("String_Node_Str");
      }
    }
    if (c == 'Z' || c == 'z') {
      separate=false;
    }
    if (c == '-' && !lastSeparate) {
      if (i == 0 || pathDataChars[i - 1] != 'e') {
        pathBuffer.append("String_Node_Str");
      }
    }
    if (c != ',') {
      pathBuffer.append(c);
    }
    if (separate && c != ',' && c != '-') {
      pathBuffer.append("String_Node_Str");
    }
    lastSeparate=separate;
  }
  String[] pathTokens=PApplet.splitTokens(pathBuffer.toString(),"String_Node_Str" + WHITESPACE);
  vertices=new float[pathTokens.length][2];
  vertexCodes=new int[pathTokens.length];
  float cx=0;
  float cy=0;
  int i=0;
  char implicitCommand='\0';
  boolean prevCurve=false;
  float ctrlX, ctrlY;
  float movetoX=0;
  float movetoY=0;
  while (i < pathTokens.length) {
    char c=pathTokens[i].charAt(0);
    if (((c >= '0' && c <= '9') || (c == '-')) && implicitCommand != '\0') {
      c=implicitCommand;
      i--;
    }
 else {
      implicitCommand=c;
    }
switch (c) {
case 'M':
      cx=PApplet.parseFloat(pathTokens[i + 1]);
    cy=PApplet.parseFloat(pathTokens[i + 2]);
  movetoX=cx;
movetoY=cy;
parsePathMoveto(cx,cy);
implicitCommand='L';
i+=3;
break;
case 'm':
cx=cx + PApplet.parseFloat(pathTokens[i + 1]);
cy=cy + PApplet.parseFloat(pathTokens[i + 2]);
parsePathMoveto(cx,cy);
implicitCommand='l';
i+=3;
break;
case 'L':
cx=PApplet.parseFloat(pathTokens[i + 1]);
cy=PApplet.parseFloat(pathTokens[i + 2]);
parsePathLineto(cx,cy);
i+=3;
break;
case 'l':
cx=cx + PApplet.parseFloat(pathTokens[i + 1]);
cy=cy + PApplet.parseFloat(pathTokens[i + 2]);
parsePathLineto(cx,cy);
i+=3;
break;
case 'H':
cx=PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'h':
cx=cx + PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'V':
cy=PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'v':
cy=cy + PApplet.parseFloat(pathTokens[i + 1]);
parsePathLineto(cx,cy);
i+=2;
break;
case 'C':
{
float ctrlX1=PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY1=PApplet.parseFloat(pathTokens[i + 2]);
float ctrlX2=PApplet.parseFloat(pathTokens[i + 3]);
float ctrlY2=PApplet.parseFloat(pathTokens[i + 4]);
float endX=PApplet.parseFloat(pathTokens[i + 5]);
float endY=PApplet.parseFloat(pathTokens[i + 6]);
parsePathCurveto(ctrlX1,ctrlY1,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=7;
prevCurve=true;
}
break;
case 'c':
{
float ctrlX1=cx + PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY1=cy + PApplet.parseFloat(pathTokens[i + 2]);
float ctrlX2=cx + PApplet.parseFloat(pathTokens[i + 3]);
float ctrlY2=cy + PApplet.parseFloat(pathTokens[i + 4]);
float endX=cx + PApplet.parseFloat(pathTokens[i + 5]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 6]);
parsePathCurveto(ctrlX1,ctrlY1,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=7;
prevCurve=true;
}
break;
case 'S':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float ctrlX2=PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY2=PApplet.parseFloat(pathTokens[i + 2]);
float endX=PApplet.parseFloat(pathTokens[i + 3]);
float endY=PApplet.parseFloat(pathTokens[i + 4]);
parsePathCurveto(ctrlX,ctrlY,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 's':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float ctrlX2=cx + PApplet.parseFloat(pathTokens[i + 1]);
float ctrlY2=cy + PApplet.parseFloat(pathTokens[i + 2]);
float endX=cx + PApplet.parseFloat(pathTokens[i + 3]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 4]);
parsePathCurveto(ctrlX,ctrlY,ctrlX2,ctrlY2,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 'Q':
{
ctrlX=PApplet.parseFloat(pathTokens[i + 1]);
ctrlY=PApplet.parseFloat(pathTokens[i + 2]);
float endX=PApplet.parseFloat(pathTokens[i + 3]);
float endY=PApplet.parseFloat(pathTokens[i + 4]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 'q':
{
ctrlX=cx + PApplet.parseFloat(pathTokens[i + 1]);
ctrlY=cy + PApplet.parseFloat(pathTokens[i + 2]);
float endX=cx + PApplet.parseFloat(pathTokens[i + 3]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 4]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=5;
prevCurve=true;
}
break;
case 'T':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float endX=PApplet.parseFloat(pathTokens[i + 1]);
float endY=PApplet.parseFloat(pathTokens[i + 2]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=3;
prevCurve=true;
}
break;
case 't':
{
if (!prevCurve) {
ctrlX=cx;
ctrlY=cy;
}
 else {
float ppx=vertices[vertexCount - 2][X];
float ppy=vertices[vertexCount - 2][Y];
float px=vertices[vertexCount - 1][X];
float py=vertices[vertexCount - 1][Y];
ctrlX=px + (px - ppx);
ctrlY=py + (py - ppy);
}
float endX=cx + PApplet.parseFloat(pathTokens[i + 1]);
float endY=cy + PApplet.parseFloat(pathTokens[i + 2]);
parsePathQuadto(ctrlX,ctrlY,endX,endY);
cx=endX;
cy=endY;
i+=3;
prevCurve=true;
}
break;
case 'Z':
case 'z':
cx=movetoX;
cy=movetoY;
close=true;
i++;
break;
default :
String parsed=PApplet.join(PApplet.subset(pathTokens,0,i),"String_Node_Str");
String unparsed=PApplet.join(PApplet.subset(pathTokens,i),"String_Node_Str");
System.err.println("String_Node_Str" + parsed);
System.err.println("String_Node_Str" + unparsed);
if (pathTokens[i].equals("String_Node_Str") || pathTokens[i].equals("String_Node_Str")) {
String msg="String_Node_Str" + "String_Node_Str";
throw new RuntimeException(msg);
}
throw new RuntimeException("String_Node_Str" + pathTokens[i]);
}
}
}