Program: 91722
Project: 91722
Buggy source:
/** 
 * Decodes the given MGRS reference.
 * @param owner  the {@code Coder} which is creating this {@code Decoder}.
 */
Decoder(final Coder owner,final CharSequence reference) throws TransformException {
  super(owner.getReferenceSystem().rootType(),reference);
  final int zone;
  boolean hasSquareIdentification;
  final double φs;
  final double λ0;
  boolean isValid=true;
  final int end=CharSequences.skipTrailingWhitespaces(reference,0,reference.length());
  final int base=CharSequences.skipLeadingWhitespaces(reference,0,end);
  int i=endOfDigits(reference,base,end);
  if (i == base && i < end) {
    zone=0;
    boolean south=false;
    boolean west=false;
    int col=0, row=0;
    for (int part=0; part <= 2; part++) {
      int c=Character.codePointAt(reference,i);
      final int ni=i + Character.charCount(c);
      if (isLetter(c) || isLetter(c-=('a' - 'A'))) {
        parse: switch (part) {
case 0:
{
switch (c) {
case 'A':
              south=true;
            west=true;
          break;
case 'B':
        south=true;
      break;
case 'Y':
    west=true;
  break;
case 'Z':
break;
default :
break parse;
}
i=nextComponent(owner,reference,base,ni,end);
continue;
}
case 1:
{
col=Arrays.binarySearch(POLAR_COLUMNS,(byte)c);
if (col < 0) break;
if (west) col-=POLAR_COLUMNS.length;
col+=(int)(PolarStereographicA.UPS_SHIFT / GRID_SQUARE_SIZE);
i=nextComponent(owner,reference,base,ni,end);
continue;
}
case 2:
{
if (c >= EXCLUDE_O) c--;
if (c >= EXCLUDE_I) c--;
row=(c - 'A') + owner.getReferenceSystem().polarOffset(south);
i=ni;
continue;
}
}
}
final short key;
final CharSequence token;
if (part == 0) {
key=Resources.Keys.IllegalUPSZone_1;
token=reference.subSequence(i,ni);
}
 else {
key=Resources.Keys.IllegalSquareIdentification_1;
token=CharSequences.token(reference,i);
}
throw new GazetteerException(Resources.format(key,token));
}
crs=owner.projection(φs=(south ? Latitude.MIN_VALUE : Latitude.MAX_VALUE),0);
minX=col * GRID_SQUARE_SIZE;
minY=row * GRID_SQUARE_SIZE;
hasSquareIdentification=true;
λ0=0;
}
 else {
zone=parseInt(reference,base,i,Resources.Keys.IllegalUTMZone_1);
if (zone < 1 || zone > 60) {
throw new GazetteerException(Resources.format(Resources.Keys.IllegalUTMZone_1,zone));
}
int latitudeBand=-1;
int col=1, row=0;
hasSquareIdentification=true;
for (int part=0; part <= 2; part++) {
if (part == 1 && i >= end) {
hasSquareIdentification=false;
break;
}
i=nextComponent(owner,reference,base,i,end);
int c=Character.codePointAt(reference,i);
final int ni=i + Character.charCount(c);
if (!isLetter(c) && !isLetter(c-=('a' - 'A'))) {
final short key;
final CharSequence token;
if (part == 0) {
key=Resources.Keys.IllegalLatitudeBand_1;
token=reference.subSequence(i,ni);
}
 else {
key=Resources.Keys.IllegalSquareIdentification_1;
token=CharSequences.token(reference,i);
}
throw new GazetteerException(Resources.format(key,token));
}
if (c >= EXCLUDE_O) c--;
if (c >= EXCLUDE_I) c--;
switch (part) {
case 0:
{
latitudeBand=(c - 'C');
break;
}
case 1:
{
switch (zone % 3) {
case 1:
col=c - ('A' - 1);
break;
case 2:
col=c - ('J' - 2);
break;
case 0:
col=c - ('S' - 3);
break;
}
break;
}
case 2:
{
if ((zone & 1) != 0) {
row=c - 'A';
}
 else {
row=c - 'F';
if (row < 0) {
row+=GRID_ROW_COUNT;
}
}
break;
}
}
i=ni;
}
φs=latitudeBand * LATITUDE_BAND_HEIGHT + TransverseMercator.Zoner.SOUTH_BOUNDS;
if (latitudeBand < 0 || latitudeBand >= ROW_RESOLVER.length) {
throw new GazetteerException(Resources.format(Resources.Keys.IllegalLatitudeBand_1,Encoder.latitudeBand(φs)));
}
λ0=ZONER.centralMeridian(zone);
crs=owner.projection(Math.signum(φs),λ0);
final int info=ROW_RESOLVER[latitudeBand];
if (hasSquareIdentification) {
int rowBit=1 << (row + NORTHING_BITS_COUNT);
isValid=(info & rowBit) != 0;
if (isValid) {
rowBit=Integer.lowestOneBit(~(info | (rowBit - 1)));
}
if ((info & -rowBit) != 0) {
row+=GRID_ROW_COUNT;
}
}
row+=(info & NORTHING_BITS_MASK) * GRID_ROW_COUNT;
minX=col * GRID_SQUARE_SIZE;
minY=row * GRID_SQUARE_SIZE;
}
final double sx, sy;
if (i < end) {
i=nextComponent(owner,reference,base,i,end);
int s=endOfDigits(reference,i,end);
final double x, y;
if (s >= end) {
int length=s - i;
if ((length & 1) != 0) {
throw new GazetteerException(Resources.format(Resources.Keys.OddGridCoordinateLength_1,reference.subSequence(i,s)));
}
final int h=i + (length>>>=1);
sx=sy=MathFunctions.pow10(METRE_PRECISION_DIGITS - length);
x=parseCoordinate(reference,i,h,sx);
y=parseCoordinate(reference,h,s,sy);
}
 else {
sx=MathFunctions.pow10(METRE_PRECISION_DIGITS - (s - i));
x=parseCoordinate(reference,i,s,sx);
i=nextComponent(owner,reference,base,s,end);
s=endOfDigits(reference,i,end);
sy=MathFunctions.pow10(METRE_PRECISION_DIGITS - (s - i));
y=parseCoordinate(reference,i,s,sy);
if (s < end) {
throw new GazetteerException(Errors.format(Errors.Keys.UnexpectedCharactersAfter_2,reference.subSequence(base,s),CharSequences.trimWhitespaces(reference,s,end)));
}
}
minX+=x;
minY+=y;
}
 else if (hasSquareIdentification) {
sx=sy=GRID_SQUARE_SIZE;
}
 else {
sx=(ZONER.easting - GRID_SQUARE_SIZE) * 2;
sy=ZONER.northing;
}
maxX=minX + sx;
maxY=minY + sy;
if (!hasSquareIdentification) {
if (zone != 0) {
if (φs < 0) {
southBoundLatitude=TransverseMercator.Zoner.SOUTH_BOUNDS;
northBoundLatitude=0;
}
 else {
southBoundLatitude=0;
northBoundLatitude=TransverseMercator.Zoner.NORTH_BOUNDS;
}
westBoundLongitude=λ0 - ZONER.width / 2;
eastBoundLongitude=λ0 + ZONER.width / 2;
}
 else {
if (φs < 0) {
southBoundLatitude=Latitude.MIN_VALUE;
northBoundLatitude=TransverseMercator.Zoner.SOUTH_BOUNDS;
}
 else {
southBoundLatitude=TransverseMercator.Zoner.NORTH_BOUNDS;
northBoundLatitude=Latitude.MAX_VALUE;
}
westBoundLongitude=Longitude.MIN_VALUE;
eastBoundLongitude=Longitude.MAX_VALUE;
}
}
 else {
final MathTransform projection=crs.getConversionFromBase().getMathTransform();
computeGeographicBoundingBox(projection.inverse());
setTypeToChild();
if (sx < GRID_SQUARE_SIZE || sy < GRID_SQUARE_SIZE) {
setTypeToChild();
}
if (isValid && zone != 0) {
final double λ=(westBoundLongitude + eastBoundLongitude) / 2;
final double φ=(southBoundLatitude + northBoundLatitude) / 2;
isValid=(φ >= φs - LATITUDE_BAND_HEIGHT / 2) && (φ < upperBound(φs));
if (isValid) {
int zoneError=ZONER.zone(φ,λ) - zone;
if (zoneError != 0) {
final int zc=ZONER.zoneCount();
if (zoneError > zc / 2) zoneError-=zc;
if (ZONER.isSpecialCase(zone,φ)) {
isValid=Math.abs(zoneError) == 1;
}
 else {
final double rλ=Math.IEEEremainder(λ - ZONER.origin,ZONER.width);
final double cv=(minX - ZONER.easting) / (λ - λ0);
isValid=(Math.abs(rλ) * cv <= sx);
if (isValid) {
isValid=(zoneError == (rλ < 0 ? -1 : +1));
}
}
}
}
}
if (isValid && owner.getClipToValidArea()) {
final boolean changed;
if (zone != 0) {
double width=ZONER.width;
if (!ZONER.isSpecialCase(zone,φs)) width/=2;
changed=clipGeographicBoundingBox(λ0 - width,φs,λ0 + width,upperBound(φs));
}
 else if (φs < 0) {
changed=clipGeographicBoundingBox(Longitude.MIN_VALUE,Latitude.MIN_VALUE,Longitude.MAX_VALUE,TransverseMercator.Zoner.SOUTH_BOUNDS);
}
 else {
changed=clipGeographicBoundingBox(Longitude.MIN_VALUE,TransverseMercator.Zoner.NORTH_BOUNDS,Longitude.MAX_VALUE,Latitude.MAX_VALUE);
}
if (changed) {
clipProjectedEnvelope(projection,sx / 100,sy / 100);
}
}
}
if (!isValid) {
final String gzd;
try {
gzd=owner.encoder(crs).encode(owner,getDirectPosition(),true,"String_Node_Str",0);
}
 catch (IllegalArgumentException|FactoryException e) {
throw new GazetteerException(e.getLocalizedMessage(),e);
}
final CharSequence ref=reference.subSequence(base,end);
throw new ReferenceVerifyException(Resources.format(Resources.Keys.InconsistentWithGZD_2,ref,gzd));
}
}

Fixed version (ground truth):
/** 
 * Decodes the given MGRS reference.
 * @param owner  the {@code Coder} which is creating this {@code Decoder}.
 */
Decoder(final Coder owner,final CharSequence reference) throws TransformException {
  super(owner.getReferenceSystem().rootType(),reference);
  final int zone;
  boolean hasSquareIdentification;
  final double φs;
  final double λ0;
  boolean isValid=true;
  final int end=CharSequences.skipTrailingWhitespaces(reference,0,reference.length());
  final int base=CharSequences.skipLeadingWhitespaces(reference,0,end);
  int i=endOfDigits(reference,base,end);
  if (i == base && i < end) {
    zone=0;
    boolean south=false;
    boolean west=false;
    int col=0, row=0;
    for (int part=0; part <= 2; part++) {
      int c=Character.codePointAt(reference,i);
      final int ni=i + Character.charCount(c);
      if (isLetter(c) || isLetter(c-=('a' - 'A'))) {
        parse: switch (part) {
case 0:
{
switch (c) {
case 'A':
              south=true;
            west=true;
          break;
case 'B':
        south=true;
      break;
case 'Y':
    west=true;
  break;
case 'Z':
break;
default :
break parse;
}
i=nextComponent(owner,reference,base,ni,end);
continue;
}
case 1:
{
col=Arrays.binarySearch(POLAR_COLUMNS,(byte)c);
if (col < 0) break;
if (west) col-=POLAR_COLUMNS.length;
col+=PolarStereographicA.UPS_SHIFT / GRID_SQUARE_SIZE;
i=nextComponent(owner,reference,base,ni,end);
continue;
}
case 2:
{
if (c >= EXCLUDE_O) c--;
if (c >= EXCLUDE_I) c--;
row=(c - 'A') + owner.getReferenceSystem().polarOffset(south);
i=ni;
continue;
}
}
}
final short key;
final CharSequence token;
if (part == 0) {
key=Resources.Keys.IllegalUPSZone_1;
token=reference.subSequence(i,ni);
}
 else {
key=Resources.Keys.IllegalSquareIdentification_1;
token=CharSequences.token(reference,i);
}
throw new GazetteerException(Resources.format(key,token));
}
crs=owner.projection(φs=(south ? Latitude.MIN_VALUE : Latitude.MAX_VALUE),0);
minX=col * GRID_SQUARE_SIZE;
minY=row * GRID_SQUARE_SIZE;
hasSquareIdentification=true;
λ0=0;
}
 else {
zone=parseInt(reference,base,i,Resources.Keys.IllegalUTMZone_1);
if (zone < 1 || zone > 60) {
throw new GazetteerException(Resources.format(Resources.Keys.IllegalUTMZone_1,zone));
}
int latitudeBand=-1;
int col=1, row=0;
hasSquareIdentification=true;
for (int part=0; part <= 2; part++) {
if (part == 1 && i >= end) {
hasSquareIdentification=false;
break;
}
i=nextComponent(owner,reference,base,i,end);
int c=Character.codePointAt(reference,i);
final int ni=i + Character.charCount(c);
if (!isLetter(c) && !isLetter(c-=('a' - 'A'))) {
final short key;
final CharSequence token;
if (part == 0) {
key=Resources.Keys.IllegalLatitudeBand_1;
token=reference.subSequence(i,ni);
}
 else {
key=Resources.Keys.IllegalSquareIdentification_1;
token=CharSequences.token(reference,i);
}
throw new GazetteerException(Resources.format(key,token));
}
if (c >= EXCLUDE_O) c--;
if (c >= EXCLUDE_I) c--;
switch (part) {
case 0:
{
latitudeBand=(c - 'C');
break;
}
case 1:
{
switch (zone % 3) {
case 1:
col=c - ('A' - 1);
break;
case 2:
col=c - ('J' - 2);
break;
case 0:
col=c - ('S' - 3);
break;
}
break;
}
case 2:
{
if ((zone & 1) != 0) {
row=c - 'A';
}
 else {
row=c - 'F';
if (row < 0) {
row+=GRID_ROW_COUNT;
}
}
break;
}
}
i=ni;
}
φs=latitudeBand * LATITUDE_BAND_HEIGHT + TransverseMercator.Zoner.SOUTH_BOUNDS;
if (latitudeBand < 0 || latitudeBand >= ROW_RESOLVER.length) {
throw new GazetteerException(Resources.format(Resources.Keys.IllegalLatitudeBand_1,Encoder.latitudeBand(φs)));
}
λ0=ZONER.centralMeridian(zone);
crs=owner.projection(Math.signum(φs),λ0);
final int info=ROW_RESOLVER[latitudeBand];
if (hasSquareIdentification) {
int rowBit=1 << (row + NORTHING_BITS_COUNT);
isValid=(info & rowBit) != 0;
if (isValid) {
rowBit=Integer.lowestOneBit(~(info | (rowBit - 1)));
}
if ((info & -rowBit) != 0) {
row+=GRID_ROW_COUNT;
}
}
row+=(info & NORTHING_BITS_MASK) * GRID_ROW_COUNT;
minX=col * GRID_SQUARE_SIZE;
minY=row * GRID_SQUARE_SIZE;
}
final double sx, sy;
if (i < end) {
i=nextComponent(owner,reference,base,i,end);
int s=endOfDigits(reference,i,end);
final double x, y;
if (s >= end) {
int length=s - i;
if ((length & 1) != 0) {
throw new GazetteerException(Resources.format(Resources.Keys.OddGridCoordinateLength_1,reference.subSequence(i,s)));
}
final int h=i + (length>>>=1);
sx=sy=MathFunctions.pow10(METRE_PRECISION_DIGITS - length);
x=parseCoordinate(reference,i,h,sx);
y=parseCoordinate(reference,h,s,sy);
}
 else {
sx=MathFunctions.pow10(METRE_PRECISION_DIGITS - (s - i));
x=parseCoordinate(reference,i,s,sx);
i=nextComponent(owner,reference,base,s,end);
s=endOfDigits(reference,i,end);
sy=MathFunctions.pow10(METRE_PRECISION_DIGITS - (s - i));
y=parseCoordinate(reference,i,s,sy);
if (s < end) {
throw new GazetteerException(Errors.format(Errors.Keys.UnexpectedCharactersAfter_2,reference.subSequence(base,s),CharSequences.trimWhitespaces(reference,s,end)));
}
}
minX+=x;
minY+=y;
}
 else if (hasSquareIdentification) {
sx=sy=GRID_SQUARE_SIZE;
}
 else {
sx=(ZONER.easting - GRID_SQUARE_SIZE) * 2;
sy=ZONER.northing;
}
maxX=minX + sx;
maxY=minY + sy;
if (!hasSquareIdentification) {
if (zone != 0) {
if (φs < 0) {
southBoundLatitude=TransverseMercator.Zoner.SOUTH_BOUNDS;
northBoundLatitude=0;
}
 else {
southBoundLatitude=0;
northBoundLatitude=TransverseMercator.Zoner.NORTH_BOUNDS;
}
westBoundLongitude=λ0 - ZONER.width / 2;
eastBoundLongitude=λ0 + ZONER.width / 2;
}
 else {
if (φs < 0) {
southBoundLatitude=Latitude.MIN_VALUE;
northBoundLatitude=TransverseMercator.Zoner.SOUTH_BOUNDS;
}
 else {
southBoundLatitude=TransverseMercator.Zoner.NORTH_BOUNDS;
northBoundLatitude=Latitude.MAX_VALUE;
}
westBoundLongitude=Longitude.MIN_VALUE;
eastBoundLongitude=Longitude.MAX_VALUE;
}
}
 else {
final MathTransform projection=crs.getConversionFromBase().getMathTransform();
computeGeographicBoundingBox(projection.inverse());
setTypeToChild();
if (sx < GRID_SQUARE_SIZE || sy < GRID_SQUARE_SIZE) {
setTypeToChild();
}
if (isValid && zone != 0) {
isValid=(northBoundLatitude >= φs) && (southBoundLatitude < upperBound(φs));
if (isValid) {
final double λ=(westBoundLongitude + eastBoundLongitude) / 2;
final double φ=(southBoundLatitude + northBoundLatitude) / 2;
int zoneError=ZONER.zone(φ,λ) - zone;
if (zoneError != 0) {
final int zc=ZONER.zoneCount();
if (zoneError > zc / 2) zoneError-=zc;
if (ZONER.isSpecialCase(zone,φ)) {
isValid=Math.abs(zoneError) == 1;
}
 else {
final double rλ=Math.IEEEremainder(λ - ZONER.origin,ZONER.width);
final double cv=(minX - ZONER.easting) / (λ - λ0);
isValid=(Math.abs(rλ) * cv <= sx);
if (isValid) {
isValid=(zoneError == (rλ < 0 ? -1 : +1));
}
}
}
}
}
if (isValid && owner.getClipToValidArea()) {
final boolean changed;
if (zone != 0) {
double width=ZONER.width;
if (!ZONER.isSpecialCase(zone,φs)) width/=2;
changed=clipGeographicBoundingBox(λ0 - width,φs,λ0 + width,upperBound(φs));
}
 else if (φs < 0) {
changed=clipGeographicBoundingBox(Longitude.MIN_VALUE,Latitude.MIN_VALUE,Longitude.MAX_VALUE,TransverseMercator.Zoner.SOUTH_BOUNDS);
}
 else {
changed=clipGeographicBoundingBox(Longitude.MIN_VALUE,TransverseMercator.Zoner.NORTH_BOUNDS,Longitude.MAX_VALUE,Latitude.MAX_VALUE);
}
if (changed) {
clipProjectedEnvelope(projection,sx / 100,sy / 100);
}
}
}
if (!isValid) {
final String gzd;
try {
gzd=owner.encoder(crs).encode(owner,getDirectPosition(),true,"String_Node_Str",0);
}
 catch (IllegalArgumentException|FactoryException e) {
throw new GazetteerException(e.getLocalizedMessage(),e);
}
final CharSequence ref=reference.subSequence(base,end);
throw new ReferenceVerifyException(Resources.format(Resources.Keys.InconsistentWithGZD_2,ref,gzd));
}
}