nus-yam/ex-repair huggingface dataset:
Program: 46578
Project: 46578
Buggy source:
/** 
 * gets a snapshot of the current constant meta classes and returns it as Iterator. Modifications done using this Iterator will not cause a ConcurrentMoidificationExcpetion. If a MetaClass is removed using this Iterator, then the MetaClass will only be removed if the MetaClass was not replaced by another MetaClass in the meantime. If a MetaClass is added while using this Iterator, then it will be part of the Iteration. If a MetaClass replaces another constant meta class, then the Iteration might show two meta classes for the same class.<br/> This Iterator may not used in multiple threads.
 * @return Iterator for the constant meta classes
 */
Iterator iterator();

Fixed version (ground truth):
/** 
 * gets a snapshot of the current constant meta classes and returns it as Iterator. Modifications done using this Iterator will not cause a ConcurrentModificationException. If a MetaClass is removed using this Iterator, then the MetaClass will only be removed if the MetaClass was not replaced by another MetaClass in the meantime. If a MetaClass is added while using this Iterator, then it will be part of the Iteration. If a MetaClass replaces another constant meta class, then the Iteration might show two meta classes for the same class.<br/> This Iterator may not used in multiple threads.
 * @return Iterator for the constant meta classes
 */
Iterator iterator();
Program: 46579
Project: 46579
Buggy source:
/** 
 * Retreives a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod
 * @param name The name of the MetaMethod
 * @param args The argument types
 * @return A MetaMethod or null if it doesn't exist
 */
MetaMethod getStaticMetaMethod(String name,Object[] args);

Fixed version (ground truth):
/** 
 * Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod
 * @param name The name of the MetaMethod
 * @param args The argument types
 * @return A MetaMethod or null if it doesn't exist
 */
MetaMethod getStaticMetaMethod(String name,Object[] args);
Program: 46580
Project: 46580
Buggy source:
/** 
 * Create new TemplateSerlvet.
 */
public TemplateServlet(){
  this.cache=new WeakHashMap();
  this.engine=null;
  this.generateBy=true;
  this.fileEncodingParamVal=null;
}

Fixed version (ground truth):
/** 
 * Create new TemplateServlet.
 */
public TemplateServlet(){
  this.cache=new WeakHashMap();
  this.engine=null;
  this.generateBy=true;
  this.fileEncodingParamVal=null;
}
Program: 46581
Project: 46581
Buggy source:
/** 
 * Creates the template engine. <p/> Called by   {@link TemplateServlet#init(ServletConfig)} and returns just<code>new groovy.text.SimpleTemplateEngine()</code> if the init parameter <code>template.engine</code> is not set by the container configuration.
 * @param config Current serlvet configuration passed by the container.
 * @return The underlying template engine or <code>null</code> on error.
 */
protected TemplateEngine initTemplateEngine(ServletConfig config){
  String name=config.getInitParameter("String_Node_Str");
  if (name == null) {
    return new SimpleTemplateEngine();
  }
  try {
    return (TemplateEngine)Class.forName(name).newInstance();
  }
 catch (  InstantiationException e) {
    log("String_Node_Str" + name,e);
  }
catch (  IllegalAccessException e) {
    log("String_Node_Str" + name,e);
  }
catch (  ClassNotFoundException e) {
    log("String_Node_Str" + name,e);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Creates the template engine. <p/> Called by   {@link TemplateServlet#init(ServletConfig)} and returns just<code>new groovy.text.SimpleTemplateEngine()</code> if the init parameter <code>template.engine</code> is not set by the container configuration.
 * @param config Current servlet configuration passed by the container.
 * @return The underlying template engine or <code>null</code> on error.
 */
protected TemplateEngine initTemplateEngine(ServletConfig config){
  String name=config.getInitParameter("String_Node_Str");
  if (name == null) {
    return new SimpleTemplateEngine();
  }
  try {
    return (TemplateEngine)Class.forName(name).newInstance();
  }
 catch (  InstantiationException e) {
    log("String_Node_Str" + name,e);
  }
catch (  IllegalAccessException e) {
    log("String_Node_Str" + name,e);
  }
catch (  ClassNotFoundException e) {
    log("String_Node_Str" + name,e);
  }
  return null;
}
Program: 46582
Project: 46582
Buggy source:
/** 
 * This creates and starts the socket server on a new Thread. There is no need to call run or spawn a new thread yourself. 
 * @param groovy The GroovyShell object that evaluates the incoming text. If you need additional classes in the  classloader then configure that through this object. 
 * @param isScriptFile Whether the incoming scoket data String will be a script or a file path. 
 * @param scriptFilenameOrText This will be a groovy script or a file location depending on the argument isScriptFile. 
 * @param autoOutput whether output should be automatically echoed back to the client
 * @param port the port to listen on
 */
public GroovySocketServer(GroovyShell groovy,boolean isScriptFile,String scriptFilenameOrText,boolean autoOutput,int port){
  this.groovy=groovy;
  this.isScriptFile=isScriptFile;
  this.scriptFilenameOrText=scriptFilenameOrText;
  this.autoOutput=autoOutput;
  try {
    url=new URL("String_Node_Str",InetAddress.getLocalHost().getHostAddress(),port,"String_Node_Str");
    System.out.println("String_Node_Str" + port);
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  new Thread(this).start();
}

Fixed version (ground truth):
/** 
 * This creates and starts the socket server on a new Thread. There is no need to call run or spawn a new thread yourself. 
 * @param groovy The GroovyShell object that evaluates the incoming text. If you need additional classes in the  classloader then configure that through this object. 
 * @param isScriptFile Whether the incoming socket data String will be a script or a file path.
 * @param scriptFilenameOrText This will be a groovy script or a file location depending on the argument isScriptFile. 
 * @param autoOutput whether output should be automatically echoed back to the client
 * @param port the port to listen on
 */
public GroovySocketServer(GroovyShell groovy,boolean isScriptFile,String scriptFilenameOrText,boolean autoOutput,int port){
  this.groovy=groovy;
  this.isScriptFile=isScriptFile;
  this.scriptFilenameOrText=scriptFilenameOrText;
  this.autoOutput=autoOutput;
  try {
    url=new URL("String_Node_Str",InetAddress.getLocalHost().getHostAddress(),port,"String_Node_Str");
    System.out.println("String_Node_Str" + port);
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  new Thread(this).start();
}
Program: 46583
Project: 46583
Buggy source:
/** 
 * Stops intercepting System.out/System.err, sending output to whereever it was going when this interceptor was created.
 */
public void stop(){
  if (output) {
    System.setOut((PrintStream)out);
  }
 else {
    System.setErr((PrintStream)out);
  }
}

Fixed version (ground truth):
/** 
 * Stops intercepting System.out/System.err, sending output to wherever it was going when this interceptor was created.
 */
public void stop(){
  if (output) {
    System.setOut((PrintStream)out);
  }
 else {
    System.setErr((PrintStream)out);
  }
}
Program: 46584
Project: 46584
Buggy source:
public void onFactoryRegistration(FactoryBuilderSupport builder,String registerdName,String group){
}

Fixed version (ground truth):
public void onFactoryRegistration(FactoryBuilderSupport builder,String registeredName,String group){
}
Program: 46586
Project: 46586
Buggy source:
/** 
 * Called when a factory is registerd to a builder
 * @param builder the build the factory has been registered to
 * @param registerdName the name the factory has been registerd under
 */
void onFactoryRegistration(FactoryBuilderSupport builder,String registerdName,String registeredGroupName);

Fixed version (ground truth):
/** 
 * Called when a factory is registered to a builder
 * @param builder the build the factory has been registered to
 * @param registeredName the name the factory has been registered under
 */
void onFactoryRegistration(FactoryBuilderSupport builder,String registeredName,String registeredGroupName);
Program: 46587
Project: 46587
Buggy source:
/** 
 * Does this factory "Own" it's child closure.
 * @return true  if the factory should have onContentClosure() called,false if the builder shouold handle it
 */
boolean isHandlesNodeChildren();

Fixed version (ground truth):
/** 
 * Does this factory "Own" it's child closure.
 * @return true  if the factory should have onContentClosure() called,false if the builder should handle it
 */
boolean isHandlesNodeChildren();
Program: 46588
Project: 46588
Buggy source:
/** 
 * This method is responsible for instanciating a node and configure its properties.
 * @param name       the name of the node
 * @param attributes the attributes for the node
 * @param value      the value arguments for the node
 * @return the object return from the factory
 */
protected Object createNode(Object name,Map attributes,Object value){
  Object node;
  Factory factory=getProxyBuilder().resolveFactory(name,attributes,value);
  if (factory == null) {
    LOG.log(Level.WARNING,"String_Node_Str" + name + "String_Node_Str");
    throw new MissingMethodExceptionNoStack((String)name,Object.class,new Object[]{attributes,value});
  }
  getProxyBuilder().getContext().put(CURRENT_FACTORY,factory);
  getProxyBuilder().getContext().put(CURRENT_NAME,String.valueOf(name));
  getProxyBuilder().preInstantiate(name,attributes,value);
  try {
    node=factory.newInstance(getProxyBuilder().getChildBuilder(),name,value,attributes);
    if (node == null) {
      LOG.log(Level.WARNING,"String_Node_Str" + name + "String_Node_Str");
      return null;
    }
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("String_Node_Str" + name + "String_Node_Str"+ node);
    }
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str" + name + "String_Node_Str"+ e,e);
  }
  getProxyBuilder().postInstantiate(name,attributes,node);
  getProxyBuilder().handleNodeAttributes(node,attributes);
  return node;
}

Fixed version (ground truth):
/** 
 * This method is responsible for instantiating a node and configure its properties.
 * @param name       the name of the node
 * @param attributes the attributes for the node
 * @param value      the value arguments for the node
 * @return the object return from the factory
 */
protected Object createNode(Object name,Map attributes,Object value){
  Object node;
  Factory factory=getProxyBuilder().resolveFactory(name,attributes,value);
  if (factory == null) {
    LOG.log(Level.WARNING,"String_Node_Str" + name + "String_Node_Str");
    throw new MissingMethodExceptionNoStack((String)name,Object.class,new Object[]{attributes,value});
  }
  getProxyBuilder().getContext().put(CURRENT_FACTORY,factory);
  getProxyBuilder().getContext().put(CURRENT_NAME,String.valueOf(name));
  getProxyBuilder().preInstantiate(name,attributes,value);
  try {
    node=factory.newInstance(getProxyBuilder().getChildBuilder(),name,value,attributes);
    if (node == null) {
      LOG.log(Level.WARNING,"String_Node_Str" + name + "String_Node_Str");
      return null;
    }
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("String_Node_Str" + name + "String_Node_Str"+ node);
    }
  }
 catch (  Exception e) {
    throw new RuntimeException("String_Node_Str" + name + "String_Node_Str"+ e,e);
  }
  getProxyBuilder().postInstantiate(name,attributes,node);
  getProxyBuilder().handleNodeAttributes(node,attributes);
  return node;
}
Program: 46589
Project: 46589
Buggy source:
/** 
 * Resolves entities against using the suppied URL as the base for relative URLs
 * @param base The URL used to resolve relative URLs
 */
public void setEntityBaseUrl(final URL base){
  this.reader.setEntityResolver(new EntityResolver(){
    public InputSource resolveEntity(    final String publicId,    final String systemId) throws IOException {
      return new InputSource(new URL(base,systemId).openStream());
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Resolves entities against using the supplied URL as the base for relative URLs
 * @param base The URL used to resolve relative URLs
 */
public void setEntityBaseUrl(final URL base){
  this.reader.setEntityResolver(new EntityResolver(){
    public InputSource resolveEntity(    final String publicId,    final String systemId) throws IOException {
      return new InputSource(new URL(base,systemId).openStream());
    }
  }
);
}
Program: 46590
Project: 46590
Buggy source:
/** 
 * Returns the detail message string of this error. The message  will consist of the bug text prefixed by "BUG! " if there this isntance was created using a message. If this error was  constructed without using a bug text the message of the cause  is used prefixed by "BUG! UNCAUGHT EXCEPTION: "
 * @return the detail message string of this error.
 */
public String getMessage(){
  if (message != null) {
    return "String_Node_Str" + message;
  }
 else {
    return "String_Node_Str" + exception.getMessage();
  }
}

Fixed version (ground truth):
/** 
 * Returns the detail message string of this error. The message  will consist of the bug text prefixed by "BUG! " if there this instance was created using a message. If this error was constructed without using a bug text the message of the cause  is used prefixed by "BUG! UNCAUGHT EXCEPTION: "
 * @return the detail message string of this error.
 */
public String getMessage(){
  if (message != null) {
    return "String_Node_Str" + message;
  }
 else {
    return "String_Node_Str" + exception.getMessage();
  }
}
Program: 46591
Project: 46591
Buggy source:
/** 
 * Adds the class pathes (if any)
 * @param classLoader the classloader to configure
 */
protected void addClassPathes(final GroovyClassLoader classLoader){
  if (classpath != null) {
    for (int i=0; i < classpath.list().length; i++) {
      classLoader.addClasspath(classpath.list()[i]);
    }
  }
}

Fixed version (ground truth):
/** 
 * Adds the class paths (if any)
 * @param classLoader the classloader to configure
 */
protected void addClassPathes(final GroovyClassLoader classLoader){
  if (classpath != null) {
    for (int i=0; i < classpath.list().length; i++) {
      classLoader.addClasspath(classpath.list()[i]);
    }
  }
}
Program: 46592
Project: 46592
Buggy source:
public Set<java.util.Map.Entry<K,V>> entrySet(){
  Map m;
  if (size < maxListFill) {
    m=innerMap;
  }
 else {
    m=makeMap();
  }
  return m.entrySet();
}

Fixed version (ground truth):
public Set<java.util.Map.Entry<K,V>> entrySet(){
  Map m;
  if (size > maxListFill) {
    m=innerMap;
  }
 else {
    m=makeMap();
  }
  return m.entrySet();
}
Program: 46593
Project: 46593
Buggy source:
private Map<K,V> makeMap(){
  Map<K,V> m=new HashMap();
  for (int i=0; i < maxListFill; i++) {
    m.put((K)listKeys[i],(V)listValues[i]);
  }
  return m;
}

Fixed version (ground truth):
private Map<K,V> makeMap(){
  Map<K,V> m=new HashMap();
  for (int i=0; i < size; i++) {
    m.put((K)listKeys[i],(V)listValues[i]);
  }
  return m;
}
Program: 46594
Project: 46594
Buggy source:
/** 
 * Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.
 */
public void cleanUpNullReferences(){
  final Iterator<Map.Entry<Object,Object>> iterator=cache.entrySet().iterator();
  while (iterator.hasNext()) {
    final Map.Entry<Object,Object> entry=iterator.next();
    if (((SoftReference)entry.getValue()).get() == null)     cache.remove(entry.getKey(),entry.getValue());
  }
}

Fixed version (ground truth):
/** 
 * Replying on the ConcurrentHashMap thread-safe iteration implementation the method will remove all entries holding SoftReferences to gc-evicted objects.
 */
public void cleanUpNullReferences(){
  final Iterator<Map.Entry<Object,Object>> iterator=cache.entrySet().iterator();
  while (iterator.hasNext()) {
    final Map.Entry<Object,Object> entry=iterator.next();
    Object entryVal=entry.getValue();
    if (entryVal != null && ((SoftReference)entryVal).get() == null)     cache.remove(entry.getKey(),entryVal);
  }
}
Program: 46595
Project: 46595
Buggy source:
/** 
 * Returns the string representation of this map.  The string displays the contents of the map, i.e. <code>[one:1, two:2, three:3]</code>.
 * @param self a Map
 * @return the string representation
 * @since 1.0
 */
public static String toMapString(Map self){
  return (self == null) ? "String_Node_Str" : InvokerHelper.toMapString(self);
}

Fixed version (ground truth):
/** 
 * Returns the string representation of this map.  The string displays the contents of the map, i.e. <code>[one:1, two:2, three:3]</code>.
 * @param self a Map
 * @param maxSize stop after approximately this many characters and append '...'
 * @return the string representation
 * @since 1.0
 */
public static String toMapString(Map self,int maxSize){
  return (self == null) ? "String_Node_Str" : InvokerHelper.toMapString(self,maxSize);
}
Program: 46596
Project: 46596
Buggy source:
/** 
 * Returns the string representation of the given list.  The string displays the contents of the list, similar to a list literal, i.e. <code>[1, 2, a]</code>.
 * @param self a Collection
 * @return the string representation
 * @since 1.0
 */
public static String toListString(Collection self){
  return (self == null) ? "String_Node_Str" : InvokerHelper.toListString(self);
}

Fixed version (ground truth):
/** 
 * Returns the string representation of the given list.  The string displays the contents of the list, similar to a list literal, i.e. <code>[1, 2, a]</code>.
 * @param self a Collection
 * @param maxSize stop after approximately this many characters and append '...'
 * @return the string representation
 * @since 1.7.3
 */
public static String toListString(Collection self,int maxSize){
  return (self == null) ? "String_Node_Str" : InvokerHelper.toListString(self,maxSize);
}
Program: 46597
Project: 46597
Buggy source:
/** 
 * A helper method to return the string representation of a map with bracket boundaries "[" and "]".
 * @param arg the map to process
 * @return the string representation of the map
 */
public static String toMapString(Map arg){
  return formatMap(arg,false);
}

Fixed version (ground truth):
/** 
 * A helper method to return the string representation of a map with bracket boundaries "[" and "]".
 * @param arg the map to process
 * @param maxSize stop after approximately this many characters and append '...'
 * @return the string representation of the map
 */
public static String toMapString(Map arg,int maxSize){
  return formatMap(arg,false,maxSize);
}
Program: 46598
Project: 46598
Buggy source:
/** 
 * A helper method to return the string representation of a list with bracket boundaries "[" and "]".
 * @param arg the collection to process
 * @return the string representation of the collection
 */
public static String toListString(Collection arg){
  return formatList(arg,false);
}

Fixed version (ground truth):
/** 
 * A helper method to return the string representation of a list with bracket boundaries "[" and "]".
 * @param arg the collection to process
 * @param maxSize stop after approximately this many characters and append '...'
 * @return the string representation of the collection
 */
public static String toListString(Collection arg,int maxSize){
  return formatList(arg,false,maxSize);
}
Program: 46599
Project: 46599
Buggy source:
private static String formatMap(Map map,boolean verbose){
  if (map.isEmpty()) {
    return "String_Node_Str";
  }
  StringBuffer buffer=new StringBuffer("String_Node_Str");
  boolean first=true;
  for (Iterator iter=map.entrySet().iterator(); iter.hasNext(); ) {
    if (first) {
      first=false;
    }
 else {
      buffer.append("String_Node_Str");
    }
    Map.Entry entry=(Map.Entry)iter.next();
    buffer.append(format(entry.getKey(),verbose));
    buffer.append("String_Node_Str");
    if (entry.getValue() == map) {
      buffer.append("String_Node_Str");
    }
 else {
      buffer.append(format(entry.getValue(),verbose));
    }
  }
  buffer.append("String_Node_Str");
  return buffer.toString();
}

Fixed version (ground truth):
private static String formatMap(Map map,boolean verbose,int maxSize){
  if (map.isEmpty()) {
    return "String_Node_Str";
  }
  StringBuffer buffer=new StringBuffer("String_Node_Str");
  boolean first=true;
  for (  Object o : map.entrySet()) {
    if (first) {
      first=false;
    }
 else {
      buffer.append("String_Node_Str");
    }
    if (maxSize != -1 && buffer.length() > maxSize) {
      buffer.append("String_Node_Str");
      break;
    }
    Map.Entry entry=(Map.Entry)o;
    buffer.append(format(entry.getKey(),verbose));
    buffer.append("String_Node_Str");
    if (entry.getValue() == map) {
      buffer.append("String_Node_Str");
    }
 else {
      buffer.append(format(entry.getValue(),verbose,sizeLeft(maxSize,buffer)));
    }
  }
  buffer.append("String_Node_Str");
  return buffer.toString();
}
Program: 46600
Project: 46600
Buggy source:
protected static String format(Object arguments,boolean verbose){
  if (arguments == null) {
    final NullObject nullObject=NullObject.getNullObject();
    return (String)nullObject.getMetaClass().invokeMethod(nullObject,"String_Node_Str",EMPTY_ARGS);
  }
  if (arguments.getClass().isArray()) {
    if (arguments instanceof char[]) {
      return new String((char[])arguments);
    }
    return format(DefaultTypeTransformation.asCollection(arguments),verbose);
  }
  if (arguments instanceof Range) {
    Range range=(Range)arguments;
    if (verbose) {
      return range.inspect();
    }
 else {
      return range.toString();
    }
  }
  if (arguments instanceof Collection) {
    return formatList((Collection)arguments,verbose);
  }
  if (arguments instanceof Map) {
    return formatMap((Map)arguments,verbose);
  }
  if (arguments instanceof Element) {
    return XmlUtil.serialize((Element)arguments);
  }
  if (arguments instanceof String) {
    if (verbose) {
      String arg=((String)arguments).replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      return "String_Node_Str" + arg + "String_Node_Str";
    }
 else {
      return (String)arguments;
    }
  }
  return arguments.toString();
}

Fixed version (ground truth):
protected static String format(Object arguments,boolean verbose,int maxSize){
  if (arguments == null) {
    final NullObject nullObject=NullObject.getNullObject();
    return (String)nullObject.getMetaClass().invokeMethod(nullObject,"String_Node_Str",EMPTY_ARGS);
  }
  if (arguments.getClass().isArray()) {
    if (arguments instanceof char[]) {
      return new String((char[])arguments);
    }
    return format(DefaultTypeTransformation.asCollection(arguments),verbose);
  }
  if (arguments instanceof Range) {
    Range range=(Range)arguments;
    if (verbose) {
      return range.inspect();
    }
 else {
      return range.toString();
    }
  }
  if (arguments instanceof Collection) {
    return formatList((Collection)arguments,verbose,maxSize);
  }
  if (arguments instanceof Map) {
    return formatMap((Map)arguments,verbose,maxSize);
  }
  if (arguments instanceof Element) {
    return XmlUtil.serialize((Element)arguments);
  }
  if (arguments instanceof String) {
    if (verbose) {
      String arg=((String)arguments).replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      arg=arg.replaceAll("String_Node_Str","String_Node_Str");
      return "String_Node_Str" + arg + "String_Node_Str";
    }
 else {
      return (String)arguments;
    }
  }
  return arguments.toString();
}
Program: 46601
Project: 46601
Buggy source:
private static String formatList(Collection list,boolean verbose){
  StringBuffer buffer=new StringBuffer("String_Node_Str");
  boolean first=true;
  for (Iterator iter=list.iterator(); iter.hasNext(); ) {
    if (first) {
      first=false;
    }
 else {
      buffer.append("String_Node_Str");
    }
    buffer.append(format(iter.next(),verbose));
  }
  buffer.append("String_Node_Str");
  return buffer.toString();
}

Fixed version (ground truth):
private static String formatList(Collection collection,boolean verbose,int maxSize){
  StringBuffer buffer=new StringBuffer("String_Node_Str");
  boolean first=true;
  for (  Object item : collection) {
    if (first) {
      first=false;
    }
 else {
      buffer.append("String_Node_Str");
    }
    if (maxSize != -1 && buffer.length() > maxSize) {
      buffer.append("String_Node_Str");
      break;
    }
    if (item == collection) {
      buffer.append("String_Node_Str");
    }
 else {
      buffer.append(format(item,verbose,sizeLeft(maxSize,buffer)));
    }
  }
  buffer.append("String_Node_Str");
  return buffer.toString();
}
Program: 46603
Project: 46603
Buggy source:
private ConstructorCallExpression getFirstIfSpecialConstructorCall(Statement code){
  if (code == null || !(code instanceof ExpressionStatement))   return null;
  Expression expression=((ExpressionStatement)code).getExpression();
  if (!(expression instanceof ConstructorCallExpression))   return null;
  ConstructorCallExpression cce=(ConstructorCallExpression)expression;
  if (cce.isSpecialCall())   return cce;
  return null;
}

Fixed version (ground truth):
private ConstructorCallExpression getFirstIfSpecialConstructorCall(BlockStatement code){
  if (code == null)   return null;
  final List<Statement> statementList=code.getStatements();
  if (statementList.isEmpty())   return null;
  final Statement statement=statementList.get(0);
  if (!(statement instanceof ExpressionStatement))   return null;
  Expression expression=((ExpressionStatement)statement).getExpression();
  if (!(expression instanceof ConstructorCallExpression))   return null;
  ConstructorCallExpression cce=(ConstructorCallExpression)expression;
  if (cce.isSpecialCall())   return cce;
  return null;
}
Program: 46604
Project: 46604
Buggy source:
private void buildSaveLiveCartQuery(){
  IAddress sadr=cart.getShippingAddress();
  String shipingAddress1=null;
  String shppingAddress2=null;
  String shippingCity=null;
  String shippingState=null;
  String shippingZip=null;
  shipingAddress1=sadr.getStreet1();
  shppingAddress2=sadr.getStreet2();
  shippingCity=sadr.getCity();
  shippingState=sadr.getState();
  shippingZip=sadr.getZip();
  IAddress badr=cart.getBillingAddress();
  String billingAddress1=null;
  String billingAddress2=null;
  String billingCity=null;
  String billingState=null;
  String billingZip=null;
  billingAddress1=badr.getStreet1();
  billingAddress2=badr.getStreet2();
  billingCity=badr.getCity();
  billingState=badr.getState();
  billingZip=badr.getZip();
  double totalPriceAmount=0;
  for (  ICartItem cit : cart.getCartItems()) {
    String tp=cit.getTotalprice();
    double tpp=Double.parseDouble(tp);
    totalPriceAmount+=tpp;
  }
  query="String_Node_Str" + cartId + "String_Node_Str"+ custId+ "String_Node_Str"+ shipingAddress1+ "String_Node_Str"+ shppingAddress2+ "String_Node_Str"+ shippingCity+ "String_Node_Str"+ shippingState+ "String_Node_Str"+ shippingZip+ "String_Node_Str"+ billingAddress1+ "String_Node_Str"+ billingAddress2+ "String_Node_Str"+ billingCity+ "String_Node_Str"+ billingState+ "String_Node_Str"+ billingZip+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ totalPriceAmount+ "String_Node_Str"+ 0.0+ "String_Node_Str"+ 0.0+ "String_Node_Str"+ totalPriceAmount+ "String_Node_Str";
}

Fixed version (ground truth):
private void buildSaveLiveCartQuery(){
  custId=cart.getCustomerId();
  query="String_Node_Str" + cartId + "String_Node_Str"+ custId+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str"+ null+ "String_Node_Str";
}
Program: 46605
Project: 46605
Buggy source:
public void saveCart() throws DatabaseException {
  this.queryType=SAVE_LIVE_CART;
  DataAccessSubsystemFacade.INSTANCE.save(this);
}

Fixed version (ground truth):
public void saveCart() throws DatabaseException {
  if (cartId == null) {
    cartId=DataAccessUtil.getNextAvailShopCartId();
  }
  this.queryType=SAVE_LIVE_CART;
  DataAccessSubsystemFacade.INSTANCE.save(this);
}
Program: 46606
Project: 46606
Buggy source:
public ShoppingCart(List<ICartItem> cartItems){
  if (cartItems == null)   this.cartItems=new LinkedList<ICartItem>();
 else   this.cartItems=cartItems;
  SessionContext context=SessionContext.INSTANCE;
  ICustomerSubsystem custSs=(ICustomerSubsystem)context.get(CustomerConstants.CUSTOMER);
  updateCustomerInfo(custSs);
}

Fixed version (ground truth):
public ShoppingCart(List<ICartItem> cartItems){
  if (cartItems == null)   this.cartItems=new LinkedList<ICartItem>();
 else   this.cartItems=cartItems;
}
Program: 46607
Project: 46607
Buggy source:
public void setCustomerId(String customerId) throws DatabaseException {
  this.customerId=customerId;
  ICustomerSubsystem css=new CustomerSubsystemFacade();
  css.initializeCustomer(customerId);
  updateCustomerInfo(css);
}

Fixed version (ground truth):
public void setCustomerId(String customerId){
  this.customerId=customerId;
}
Program: 46608
Project: 46608
Buggy source:
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.search);
  Intent intent=getIntent();
  if (Intent.ACTION_SEARCH.equalsIgnoreCase(intent.getAction())) {
    String query=intent.getStringExtra(SearchManager.QUERY);
    if (Preferences.getSuggestions(getApplicationContext())) {
      SearchRecentSuggestions suggestions=new SearchRecentSuggestions(this,SuggestionProvider.AUTHORITY,SuggestionProvider.MODE);
      suggestions.saveRecentQuery(query,null);
    }
    String[] agencies=getListItems(this,SELECT + AGENCIES + WHERE+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query));
    String[] mayoralties=getListItems(this,SELECT + MAYORALTIES + WHERE+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query));
    String[] procedures=getListItems(this,SELECT + PROCEDURES + WHERE+ replace("String_Node_Str",query));
    TextView noResults=(TextView)findViewById(R.id.search_results);
    noResults.setText(Html.fromHtml(getString(R.string.search_none,query)));
    String[] results=mergeArrays(agencies,mayoralties,procedures);
    inflateList(results);
  }
}

Fixed version (ground truth):
@Override public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.search);
  Intent intent=getIntent();
  if (Intent.ACTION_SEARCH.equalsIgnoreCase(intent.getAction())) {
    String query=intent.getStringExtra(SearchManager.QUERY);
    if (Preferences.getSuggestions(getApplicationContext())) {
      SearchRecentSuggestions suggestions=new SearchRecentSuggestions(this,SuggestionProvider.AUTHORITY,SuggestionProvider.MODE);
      suggestions.saveRecentQuery(query,null);
    }
    String[] agencies=getListItems(this,AGENCIES + WHERE + replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query));
    String[] mayoralties=getListItems(this,MAYORALTIES + WHERE + replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query)+ OR+ replace("String_Node_Str",query));
    String[] procedures=getListItems(this,PROCEDURES + WHERE + replace("String_Node_Str",query));
    TextView noResults=(TextView)findViewById(R.id.search_results);
    noResults.setText(Html.fromHtml(getString(R.string.search_none,query)));
    String[] results=mergeArrays(agencies,mayoralties,procedures);
    inflateList(results);
  }
}
Program: 46609
Project: 46609
Buggy source:
private void inflateList(String[] results){
  final ListView resultsList=(ListView)findViewById(R.id.list_result);
  ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results);
  resultsList.setAdapter(adapter);
  resultsList.setOnItemClickListener(new OnItemClickListener(){
    @Override public void onItemClick(    AdapterView<?> adapter,    View view,    int position,    long id){
      String[] agenciesResults=getArrayFromCursor(Search.this,SELECT + AGENCIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
      String[] mayoraltiesResults=getArrayFromCursor(Search.this,SELECT + MAYORALTIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
      String[] proceduresResults=getArrayFromCursor(Search.this,SELECT + PROCEDURES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
      try {
        Show.setDialog(Search.this,agenciesResults);
      }
 catch (      Exception e) {
        try {
          Show.setDialog(Search.this,mayoraltiesResults);
        }
 catch (        Exception e1) {
          showActivity(Procedures.class,Integer.parseInt(proceduresResults[0]));
        }
      }
    }
  }
);
  resultsList.setVisibility(View.VISIBLE);
  resultsList.setEmptyView(findViewById(R.id.search_results));
}

Fixed version (ground truth):
private void inflateList(String[] results){
  final ListView resultsList=(ListView)findViewById(R.id.list_result);
  ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,results);
  resultsList.setAdapter(adapter);
  resultsList.setOnItemClickListener(new OnItemClickListener(){
    @Override public void onItemClick(    AdapterView<?> adapter,    View view,    int position,    long id){
      String[] agenciesResults=getArrayFromCursor(Search.this,"String_Node_Str" + AGENCIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
      String[] mayoraltiesResults=getArrayFromCursor(Search.this,"String_Node_Str" + MAYORALTIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
      String[] proceduresResults=getArrayFromCursor(Search.this,"String_Node_Str" + PROCEDURES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
      if (!agenciesResults[1].equals("String_Node_Str"))       Show.setDialog(Search.this,agenciesResults);
      if (!mayoraltiesResults[1].equals("String_Node_Str"))       Show.setDialog(Search.this,mayoraltiesResults);
      if (!proceduresResults[1].equals("String_Node_Str"))       showActivity(Procedures.class,Integer.parseInt(proceduresResults[0]));
    }
  }
);
  resultsList.setVisibility(View.VISIBLE);
  resultsList.setEmptyView(findViewById(R.id.search_results));
}
Program: 46610
Project: 46610
Buggy source:
@Override public void onItemClick(AdapterView<?> adapter,View view,int position,long id){
  String[] agenciesResults=getArrayFromCursor(Search.this,SELECT + AGENCIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
  String[] mayoraltiesResults=getArrayFromCursor(Search.this,SELECT + MAYORALTIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
  String[] proceduresResults=getArrayFromCursor(Search.this,SELECT + PROCEDURES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
  try {
    Show.setDialog(Search.this,agenciesResults);
  }
 catch (  Exception e) {
    try {
      Show.setDialog(Search.this,mayoraltiesResults);
    }
 catch (    Exception e1) {
      showActivity(Procedures.class,Integer.parseInt(proceduresResults[0]));
    }
  }
}

Fixed version (ground truth):
@Override public void onItemClick(AdapterView<?> adapter,View view,int position,long id){
  String[] agenciesResults=getArrayFromCursor(Search.this,"String_Node_Str" + AGENCIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
  String[] mayoraltiesResults=getArrayFromCursor(Search.this,"String_Node_Str" + MAYORALTIES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
  String[] proceduresResults=getArrayFromCursor(Search.this,"String_Node_Str" + PROCEDURES + WHERE+ "String_Node_Str"+ resultsList.getItemAtPosition(position).toString()+ "String_Node_Str");
  if (!agenciesResults[1].equals("String_Node_Str"))   Show.setDialog(Search.this,agenciesResults);
  if (!mayoraltiesResults[1].equals("String_Node_Str"))   Show.setDialog(Search.this,mayoraltiesResults);
  if (!proceduresResults[1].equals("String_Node_Str"))   showActivity(Procedures.class,Integer.parseInt(proceduresResults[0]));
}
Program: 46611
Project: 46611
Buggy source:
private String createSoapRequest(HashMap<String,String> requestFields){
  XmlSerializer serializer=Xml.newSerializer();
  StringWriter writer=new StringWriter();
  try {
    serializer.setOutput(writer);
    serializer.setPrefix(SOAPENV,ENV);
    serializer.setPrefix(URN_STRING,URN);
    serializer.startTag(ENV,ENVELOPE);
    serializer.startTag(ENV,HEADER);
    serializer.endTag(ENV,HEADER);
    serializer.startTag(ENV,BODY);
    serializer.startTag(URN,LOGIN);
    serializer.startTag(URN,USERNAME);
    serializer.text(requestFields.get(USERNAME));
    serializer.endTag(URN,USERNAME);
    serializer.startTag(URN,PASSWORD);
    serializer.text(requestFields.get(PASSWORD));
    serializer.text(requestFields.get(SECURITY_TOKEN));
    serializer.endTag(URN,PASSWORD);
    serializer.endTag(URN,LOGIN);
    serializer.endTag(ENV,BODY);
    serializer.endTag(ENV,ENVELOPE);
    serializer.endDocument();
    return writer.toString();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
private String createSoapRequest(HashMap<String,String> requestFields){
  XmlSerializer serializer=Xml.newSerializer();
  StringWriter writer=new StringWriter();
  try {
    serializer.setOutput(writer);
    serializer.setPrefix(SOAPENV,ENV);
    serializer.setPrefix(URN_STRING,URN);
    serializer.startTag(ENV,ENVELOPE);
    serializer.startTag(ENV,HEADER);
    serializer.endTag(ENV,HEADER);
    serializer.startTag(ENV,BODY);
    serializer.startTag(URN,LOGIN);
    serializer.startTag(URN,USERNAME);
    serializer.text(requestFields.get(USERNAME));
    serializer.endTag(URN,USERNAME);
    serializer.startTag(URN,PASSWORD);
    serializer.text(requestFields.get(PASSWORD));
    String secToken=requestFields.get(SECURITY_TOKEN);
    if (secToken != null && !secToken.trim().equals("String_Node_Str"))     serializer.text(requestFields.get(SECURITY_TOKEN));
    serializer.endTag(URN,PASSWORD);
    serializer.endTag(URN,LOGIN);
    serializer.endTag(ENV,BODY);
    serializer.endTag(ENV,ENVELOPE);
    serializer.endDocument();
    return writer.toString();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
Program: 46614
Project: 46614
Buggy source:
public SObject(String type,ArrayList<String> fieldsToNull,String id,HashMap<String,String> fields){
  this.type=type;
  this.fieldsToNull=fieldsToNull;
  this.id=id;
  this.fields=fields;
}

Fixed version (ground truth):
public SObject(String type,ArrayList<String> fieldsToNull,HashMap<String,String> fields){
  this.type=type;
  this.fieldsToNull=fieldsToNull;
  this.fields=fields;
}
Program: 46615
Project: 46615
Buggy source:
public void setId(java.lang.String id){
  this.id=id;
}

Fixed version (ground truth):
public void setId(java.lang.String id){
  setField("String_Node_Str",id);
}
Program: 46616
Project: 46616
Buggy source:
public java.lang.String getId(){
  return id;
}

Fixed version (ground truth):
public java.lang.String getId(){
  String i=this.fields.get("String_Node_Str");
  if (i == null) {
    i=this.fields.get("String_Node_Str");
    if (i == null)     i=this.fields.get("String_Node_Str");
  }
  return i;
}
Program: 46617
Project: 46617
Buggy source:
public String toString(){
  sb.append("String_Node_Str");
  sb.append("String_Node_Str").append(type).append("String_Node_Str").append("String_Node_Str").append(id).append("String_Node_Str");
  Set<String> fieldSet=fields.keySet();
  Iterator<String> itrFields=fieldSet.iterator();
  while (itrFields.hasNext()) {
    String fieldName=itrFields.next();
    sb.append(fieldName).append("String_Node_Str").append(fields.get(fieldName)).append("String_Node_Str");
  }
  return sb.toString();
}

Fixed version (ground truth):
public String toString(){
  sb.append("String_Node_Str");
  sb.append("String_Node_Str").append(type).append("String_Node_Str").append("String_Node_Str").append(getId()).append("String_Node_Str");
  Set<String> fieldSet=fields.keySet();
  Iterator<String> itrFields=fieldSet.iterator();
  while (itrFields.hasNext()) {
    String fieldName=itrFields.next();
    sb.append(fieldName).append("String_Node_Str").append(fields.get(fieldName)).append("String_Node_Str");
  }
  return sb.toString();
}
Program: 46618
Project: 46618
Buggy source:
/** 
 * Calculate the affine transform from scanStrip to a single frame (frame  rotated to straight position, top left corner translated to (0,0)
 * @param frame
 * @return
 */
AffineTransform getFrameXform(int frame){
  int f1=frame - 1;
  int f2=frame + 1;
  int x1=(f1 >= 0) ? perforations.get(f1).x : perforations.get(0).x;
  int x2=(f2 < perforations.size()) ? perforations.get(f2).x : perforations.get(perforations.size() - 1).x;
  int y1=(f1 >= 0) ? perforations.get(f1).y : perforations.get(0).y;
  int y2=(f2 < perforations.size()) ? perforations.get(f2).y : perforations.get(perforations.size() - 1).y;
  double rot=Math.atan2((double)x2 - x1,(double)(y2 - y1));
  AffineTransform xform=new AffineTransform();
  xform.translate(0,FRAME_HEIGHT / 2);
  xform.rotate(rot);
  xform.translate(-perforations.get(framePerf).x,-perforations.get(framePerf).y);
  return xform;
}

Fixed version (ground truth):
/** 
 * Calculate the affine transform from scanStrip to a single frame (frame  rotated to straight position, top left corner translated to (0,0)
 * @param frame
 * @return
 */
AffineTransform getFrameXform(int frame){
  int f1=frame - 1;
  int f2=frame + 1;
  int x1=(f1 >= 0) ? perforations.get(f1).x : perforations.get(0).x;
  int x2=(f2 < perforations.size()) ? perforations.get(f2).x : perforations.get(perforations.size() - 1).x;
  int y1=(f1 >= 0) ? perforations.get(f1).y : perforations.get(0).y;
  int y2=(f2 < perforations.size()) ? perforations.get(f2).y : perforations.get(perforations.size() - 1).y;
  double rot=Math.atan2((double)x2 - x1,(double)(y2 - y1));
  AffineTransform xform=new AffineTransform();
  xform.translate(0,FRAME_HEIGHT / 2);
  xform.rotate(rot);
  xform.translate(-perforations.get(frame).x,-perforations.get(frame).y);
  return xform;
}
Program: 46619
Project: 46619
Buggy source:
/** 
 * Creates a new NxjFilmMover
 * @throws fi.kaimio.moviescan.FilmMoverException If no connected film mover was found or other error occurred.
 */
public NxjFilmMover() throws FilmMoverException {
  nxtComm=NXTCommFactory.createNXTComm(NXTCommFactory.USB);
  NXTInfo[] nxtInfos=null;
  log.fine("String_Node_Str");
  try {
    nxtInfos=nxtComm.search(null,NXTCommFactory.USB);
  }
 catch (  NXTCommException e) {
    log.warning("String_Node_Str");
  }
  if (nxtInfos.length == 0) {
    log.warning("String_Node_Str");
    throw new FilmMoverException("String_Node_Str");
  }
  try {
    nxtInfo=nxtInfos[0];
    nxtComm.open(nxtInfo);
  }
 catch (  NXTCommException e) {
    log.warning("String_Node_Str");
    throw new FilmMoverException("String_Node_Str" + e.getMessage(),e);
  }
  InputStream is=nxtComm.getInputStream();
  OutputStream os=nxtComm.getOutputStream();
  inDat=new DataInputStream(is);
  outDat=new DataOutputStream(os);
}

Fixed version (ground truth):
/** 
 * Creates a new NxjFilmMover
 * @throws fi.kaimio.moviescan.FilmMoverException If no connected film mover was found or other error occurred.
 */
public NxjFilmMover() throws FilmMoverException {
  nxtComm=NXTCommFactory.createNXTComm(NXTCommFactory.USB);
  NXTInfo[] nxtInfos=null;
  log.fine("String_Node_Str");
  try {
    nxtInfos=nxtComm.search(null,NXTCommFactory.USB);
  }
 catch (  NXTCommException e) {
    log.warning("String_Node_Str");
  }
  if (nxtInfos == null || nxtInfos.length == 0) {
    log.warning("String_Node_Str");
    throw new FilmMoverException("String_Node_Str");
  }
  try {
    nxtInfo=nxtInfos[0];
    nxtComm.open(nxtInfo);
  }
 catch (  NXTCommException e) {
    log.warning("String_Node_Str");
    throw new FilmMoverException("String_Node_Str" + e.getMessage(),e);
  }
  InputStream is=nxtComm.getInputStream();
  OutputStream os=nxtComm.getOutputStream();
  inDat=new DataInputStream(is);
  outDat=new DataOutputStream(os);
}
Program: 46621
Project: 46621
Buggy source:
/** 
 * Add a perforation to the series if it fits. Perforation is considered a fit  if it is at the right distance (multiple of the distance between perforations) from the previous one.
 * @param p The perforation that may be added
 * @return true if the perforation fits, false otherwise.
 */
public boolean addIfFits(Perforation p){
  boolean isFit=false;
  if (perforations.size() == 0) {
    isFit=true;
    perforations.add(p);
    p.series=this;
    missCount=p.y / PERF_DISTANCE;
    lastY=p.y;
    lastX=p.x;
  }
 else {
    int dy=p.y - lastY;
    int numFrames=(int)Math.round((double)dy / PERF_DISTANCE);
    int devPixels=Math.abs(dy - PERF_DISTANCE * numFrames);
    double devRel=(double)devPixels / (PERF_DISTANCE * numFrames);
    int res=dy % PERF_DISTANCE;
    if (numFrames > 0 && (devRel < Y_TOL)) {
      isFit=true;
      perforations.add(p);
      p.series=this;
      missCount+=numFrames - 1;
      lastY=p.y;
      lastX2=lastX;
      lastX=p.x;
      if (lastX2 > 0) {
        int ddx=Math.abs(lastX2 + p.x - 2 * lastX);
        maxDdx=Math.max(ddx,maxDdx);
      }
    }
  }
  return isFit;
}

Fixed version (ground truth):
/** 
 * Add a perforation to the series if it fits. Perforation is considered a fit  if it is at the right distance (multiple of the distance between perforations) from the previous one.
 * @param p The perforation that may be added
 * @return true if the perforation fits, false otherwise.
 */
public boolean addIfFits(Perforation p){
  boolean isFit=false;
  if (perforations.size() == 0) {
    isFit=true;
    perforations.add(p);
    missCount=p.y / PERF_DISTANCE;
    lastY=p.y;
    lastX=p.x;
  }
 else {
    int dy=p.y - lastY;
    int numFrames=(int)Math.round((double)dy / PERF_DISTANCE);
    int devPixels=Math.abs(dy - PERF_DISTANCE * numFrames);
    double devRel=(double)devPixels / (PERF_DISTANCE * numFrames);
    if (numFrames > 0 && (devRel < Y_TOL)) {
      isFit=true;
      perforations.add(p);
      missCount+=numFrames - 1;
      lastY=p.y;
      lastX2=lastX;
      lastX=p.x;
      if (lastX2 > 0) {
        int ddx=Math.abs(lastX2 + p.x - 2 * lastX);
        maxDdx=Math.max(ddx,maxDdx);
      }
    }
  }
  return isFit;
}