Program: 77408
Project: 77408
Buggy source:
/** 
 * Creates a random access file stream to read from, and optionally to write to, the file specified by the   {@link File} argument.  A new {@link FileDescriptor} object is created to represent this file connection.<a name="mode"><p> The <tt>mode</tt> argument specifies the access mode in which the file is to be opened.  The permitted values and their meanings are: <blockquote><table summary="Access mode permitted values and meanings"> <tr><th><p align="left">Value</p></th><th><p align="left">Meaning</p></th></tr> <tr><td valign="top"><tt>"r"</tt></td> <td> Open for reading only.  Invoking any of the <tt>write</tt> methods of the resulting object will cause an  {@link java.io.IOException} to be thrown. </td></tr><tr><td valign="top"><tt>"rw"</tt></td> <td> Open for reading and writing.  If the file does not already exist then an attempt will be made to create it. </td></tr> <tr><td valign="top"><tt>"rws"</tt></td> <td> Open for reading and writing, as with <tt>"rw"</tt>, and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.  </td></tr> <tr><td valign="top"><tt>"rwd"&nbsp;&nbsp;</tt></td> <td> Open for reading and writing, as with <tt>"rw"</tt>, and also require that every update to the file's content be written synchronously to the underlying storage device. </td></tr> </table></blockquote> The <tt>"rws"</tt> and <tt>"rwd"</tt> modes work much like the  {@link java.nio.channels.FileChannel#force(boolean) force(boolean)} method ofthe  {@link java.nio.channels.FileChannel} class, passing arguments of<tt>true</tt> and <tt>false</tt>, respectively, except that they always apply to every I/O operation and are therefore often more efficient.  If the file resides on a local storage device then when an invocation of a method of this class returns it is guaranteed that all changes made to the file by that invocation will have been written to that device.  This is useful for ensuring that critical information is not lost in the event of a system crash.  If the file does not reside on a local device then no such guarantee is made. <p> The <tt>"rwd"</tt> mode can be used to reduce the number of I/O operations performed.  Using <tt>"rwd"</tt> only requires updates to the file's content to be written to storage; using <tt>"rws"</tt> requires updates to both the file's content and its metadata to be written, which generally requires at least one more low-level I/O operation. <p> If there is a security manager, its  {@code checkRead} method iscalled with the pathname of the  {@code file} argument as itsargument to see if read access to the file is allowed.  If the mode allows writing, the security manager's  {@code checkWrite} method isalso called with the path argument to see if write access to the file is allowed.
 * @param file   the file object
 * @param mode   the access mode, as described<a href="#mode">above</a>
 * @exception IllegalArgumentException  if the mode argument is not equalto one of <tt>"r"</tt>, <tt>"rw"</tt>, <tt>"rws"</tt>, or <tt>"rwd"</tt>
 * @exception FileNotFoundException if the mode is <tt>"r"</tt> but the given file object does not denote an existing regular file, or if the mode begins with <tt>"rw"</tt> but the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
 * @exception SecurityException         if a security manager exists and its{@code checkRead} method denies read access to the fileor the mode is "rw" and the security manager's {@code checkWrite} method denies write access to the file
 * @see java.lang.SecurityManager#checkRead(java.lang.String)
 * @see java.lang.SecurityManager#checkWrite(java.lang.String)
 * @see java.nio.channels.FileChannel#force(boolean)
 * @revised 1.4
 * @spec JSR-51
 */
public RandomAccessFile(File file,String mode) throws FileNotFoundException {
  String name=(file != null ? file.getPath() : null);
  int imode=-1;
  if (mode.equals("String_Node_Str"))   imode=O_RDONLY;
 else   if (mode.startsWith("String_Node_Str")) {
    imode=O_RDWR;
    rw=true;
    if (mode.length() > 2) {
      if (mode.equals("String_Node_Str"))       imode|=O_SYNC;
 else       if (mode.equals("String_Node_Str"))       imode|=O_DSYNC;
 else       imode=-1;
    }
  }
  if (imode < 0)   throw new IllegalArgumentException("String_Node_Str" + mode + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  SecurityManager security=System.getSecurityManager();
  if (security != null) {
    security.checkRead(name);
    if (rw) {
      security.checkWrite(name);
    }
  }
  if (name == null) {
    throw new NullPointerException();
  }
  if (file.isInvalid()) {
    throw new FileNotFoundException("String_Node_Str");
  }
  fd=new FileDescriptor();
  fd.attach(this);
  open(name,imode);
}

Fixed version (ground truth):
/** 
 * Creates a random access file stream to read from, and optionally to write to, the file specified by the   {@link File} argument.  A new {@link FileDescriptor} object is created to represent this file connection.<p>The <a name="mode"><tt>mode</tt></a> argument specifies the access mode in which the file is to be opened.  The permitted values and their meanings are: <table summary="Access mode permitted values and meanings"> <tr><th><p align="left">Value</p></th><th><p align="left">Meaning</p></th></tr> <tr><td valign="top"><tt>"r"</tt></td> <td> Open for reading only.  Invoking any of the <tt>write</tt> methods of the resulting object will cause an  {@link java.io.IOException} to be thrown. </td></tr><tr><td valign="top"><tt>"rw"</tt></td> <td> Open for reading and writing.  If the file does not already exist then an attempt will be made to create it. </td></tr> <tr><td valign="top"><tt>"rws"</tt></td> <td> Open for reading and writing, as with <tt>"rw"</tt>, and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.  </td></tr> <tr><td valign="top"><tt>"rwd"&nbsp;&nbsp;</tt></td> <td> Open for reading and writing, as with <tt>"rw"</tt>, and also require that every update to the file's content be written synchronously to the underlying storage device. </td></tr> </table> The <tt>"rws"</tt> and <tt>"rwd"</tt> modes work much like the  {@link java.nio.channels.FileChannel#force(boolean) force(boolean)} method ofthe  {@link java.nio.channels.FileChannel} class, passing arguments of<tt>true</tt> and <tt>false</tt>, respectively, except that they always apply to every I/O operation and are therefore often more efficient.  If the file resides on a local storage device then when an invocation of a method of this class returns it is guaranteed that all changes made to the file by that invocation will have been written to that device.  This is useful for ensuring that critical information is not lost in the event of a system crash.  If the file does not reside on a local device then no such guarantee is made. <p>The <tt>"rwd"</tt> mode can be used to reduce the number of I/O operations performed.  Using <tt>"rwd"</tt> only requires updates to the file's content to be written to storage; using <tt>"rws"</tt> requires updates to both the file's content and its metadata to be written, which generally requires at least one more low-level I/O operation. <p>If there is a security manager, its  {@code checkRead} method iscalled with the pathname of the  {@code file} argument as itsargument to see if read access to the file is allowed.  If the mode allows writing, the security manager's  {@code checkWrite} method isalso called with the path argument to see if write access to the file is allowed.
 * @param file   the file object
 * @param mode   the access mode, as described<a href="#mode">above</a>
 * @exception IllegalArgumentException  if the mode argument is not equalto one of <tt>"r"</tt>, <tt>"rw"</tt>, <tt>"rws"</tt>, or <tt>"rwd"</tt>
 * @exception FileNotFoundException if the mode is <tt>"r"</tt> but the given file object does not denote an existing regular file, or if the mode begins with <tt>"rw"</tt> but the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
 * @exception SecurityException         if a security manager exists and its{@code checkRead} method denies read access to the fileor the mode is "rw" and the security manager's {@code checkWrite} method denies write access to the file
 * @see java.lang.SecurityManager#checkRead(java.lang.String)
 * @see java.lang.SecurityManager#checkWrite(java.lang.String)
 * @see java.nio.channels.FileChannel#force(boolean)
 * @revised 1.4
 * @spec JSR-51
 */
public RandomAccessFile(File file,String mode) throws FileNotFoundException {
  String name=(file != null ? file.getPath() : null);
  int imode=-1;
  if (mode.equals("String_Node_Str"))   imode=O_RDONLY;
 else   if (mode.startsWith("String_Node_Str")) {
    imode=O_RDWR;
    rw=true;
    if (mode.length() > 2) {
      if (mode.equals("String_Node_Str"))       imode|=O_SYNC;
 else       if (mode.equals("String_Node_Str"))       imode|=O_DSYNC;
 else       imode=-1;
    }
  }
  if (imode < 0)   throw new IllegalArgumentException("String_Node_Str" + mode + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  SecurityManager security=System.getSecurityManager();
  if (security != null) {
    security.checkRead(name);
    if (rw) {
      security.checkWrite(name);
    }
  }
  if (name == null) {
    throw new NullPointerException();
  }
  if (file.isInvalid()) {
    throw new FileNotFoundException("String_Node_Str");
  }
  fd=new FileDescriptor();
  fd.attach(this);
  open(name,imode);
}