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

getCanonicalPath on link returns invalid result

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.4.2, 7u25
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description



      Name: rmT116609 Date: 08/10/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_04"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
      Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux totoro 2.4.19-4GB #1 Fri Apr 2 19:59:17 UTC 2004 i686 unknown

      A DESCRIPTION OF THE PROBLEM :
      getCanonicalPath on a link returns the path to the link instead of the link's target if getCanonicalPath was called before the link is actually created.

      If you comment out line 23 of the test code the correct path is returned.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Compile the attached unit test
      2) Execute the unit test (e.g. java -classpath .:junit.jar junit.textui.TestRunner LinkTest)


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The unit test should succeed.
      ACTUAL -
      The unit test fails.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      .F
      Time: 0.164
      There was 1 failure:
      1) testGetCanonicalPath(LinkTest)junit.framework.ComparisonFailure: expected:<..
      .target> but was:<...link>
              at LinkTest.testGetCanonicalPath(LinkTest.java:48)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

      FAILURES!!!
      Tests run: 1, Failures: 1, Errors: 0

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import junit.framework.*;

      public class LinkTest
          extends TestCase
      {
          private File linkFile, targetFile;

          public LinkTest()
          {
              super("LinkTest");
          }

          public void setUp()
              throws Exception
          {
              String dir = System.getProperty("user.home");
                  
              linkFile = new File(dir, "link");
              targetFile = new File(dir, "target");

              // This line seems to be the cause of the problem.
              linkFile.getCanonicalPath();

              assertTrue(targetFile.createNewFile());
                  
              String[] cmd = {
                  "ln",
                  "-s",
                  targetFile.getAbsolutePath(),
                  linkFile.getAbsolutePath(),
              };
              
              Process p = Runtime.getRuntime().exec(cmd);

              p.waitFor();
          }
          
          public void tearDown()
          {
              linkFile.delete();
              targetFile.delete();
          }

          public void testGetCanonicalPath()
              throws IOException
          {
              assertEquals(targetFile.getAbsolutePath(), linkFile.getCanonicalPath());
          }
      }

      ---------- END SOURCE ----------
      (Incident Review ID: 284849)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: