Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8054401

Please remove duplicated lines in examples

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 8
    • 7, 8
    • docs
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Grep.java is just one example ... more files are affected.

      The examples won't compile due to every few lines some code was duplicated.

      Maybe some automatic formatter tool messed up the examples on updating whitespace? Some of the lines are indented with spaces and their duplicates are indented using tabs.

      Hopefully you can resurrect a better version from some previous release?

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
          // Search for occurrences of the input pattern in the given file
          //
          private static void grep(File f) throws IOException {

              // Open the file and then get a channel from the stream
              FileInputStream fis = new FileInputStream(f);
              FileChannel fc = fis.getChannel();

              // Get the file's size and then map it into memory
              int sz = (int)fc.size();
              MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);

              // Decode the file into a char buffer
              CharBuffer cb = decoder.decode(bb);

              // Perform the search
              grep(f, cb);

              // Close the channel and the stream
              fc.close();
          }

      ACTUAL -
          // Search for occurrences of the input pattern in the given file
          //
          private static void grep(File f) throws IOException {

              // Open the file and then get a channel from the stream
              FileInputStream fis = new FileInputStream(f);
              FileChannel fc = fis.getChannel();
      // Open the file and then get a channel from the stream
      FileInputStream fis = new FileInputStream(f);
      FileChannel fc = fis.getChannel();

              // Get the file's size and then map it into memory
              int sz = (int)fc.size();
              MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
      // Get the file's size and then map it into memory
      int sz = (int)fc.size();
      MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);

              // Decode the file into a char buffer
              CharBuffer cb = decoder.decode(bb);
      // Decode the file into a char buffer
      CharBuffer cb = decoder.decode(bb);

              // Perform the search
              grep(f, cb);
      // Perform the search
      grep(f, cb);

              // Close the channel and the stream
              fc.close();
      // Close the channel and the stream
      fc.close();
          }


      URL OF FAULTY DOCUMENTATION :
      http://docs.oracle.com/javase/8/docs/technotes/guides/io/example/Grep.java

            rgallard Raymond Gallardo
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: