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

getResource() fails in Solaris when CLASSPATH includes ../..

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1.5
    • 1.1
    • core-libs
    • None
    • 1.1.5
    • sparc
    • solaris_2.5.1
    • Not verified



      Name: mc57594 Date: 03/11/97


      I call getClass().getResource("name") and receive the following
      URL: systemresource:/+/COM/ims/name. This then yields a
      malformed URL exception when I try to oepn the URL. I can
      call getClass().getResourceAsStream("name") and open the URL
      without problems. Unfortunately, I need to be able to open an
      OutputStream as well as an InputStream.

      Here is a program that can be used to duplicate the problem:

      package COM.ims;
      import java.io.*;
      import java.net.*;
      import java.util.Properties;

      class ApplicationProperties extends Properties
      {

      public
      ApplicationProperties()
      {
          super();
      }

      public
      ApplicationProperties(
          Properties properties)
      {
          super(properties);
      }

      public synchronized void
      load()
          throws IOException
      {
          init();
          load(url.openConnection().getInputStream());
      }

      public synchronized void
      save(
          String header)
          throws IOException
      {
          init();
          save(url.openConnection().getOutputStream(), header);
      }

      private URL url;

      private final void
      init()
      {
          if (url == null) {
      url = getClass().getResource("myResources.properties");
      System.out.println(url);
      InputStream in =
      getClass().getResourceAsStream("myResources.properties");
      System.out.println("Got resources as stream");
          }
      }

      static public void
      main(
          String[] args)
      {
          try {
      ApplicationProperties appProperties = new ApplicationProperties();
      appProperties.load();

      String dataPath = appProperties.getProperty("dataPath", ".");
      System.out.println(dataPath);

      appProperties.put("dataPath", System.getProperty("java_home"));
      appProperties.save("Properties title");
      System.out.println("Saved properties");
          }
          catch (IOException exception) {
      System.out.println("Caught " + exception);
          }
      }

      }

      Here is the script I use to run the program:

      #!/bin/ksh

      export JAVA_HOME=/ims/java/jdk1.1
      export PATH=$JAVA_HOME/bin:$PATH

      export CLASSPATH=
      export CLASSPATH=${CLASSPATH}:.
      export CLASSPATH=${CLASSPATH}:../..
      export CLASSPATH=${CLASSPATH}:$JAVA_HOME/lib/classes.zip

      java COM.ims.ApplicationProperties $*

      Here is the output from the program:

      systemresource:/+/COM/ims/myResources.properties
      Got resources as stream
      Caught java.net.MalformedURLException: systemresource:/+/COM/ims/myResources.properties is not a valid system resource URL

      company - Integrated Measurement Systems , email - ###@###.###
      ======================================================================

            epelegrisunw Eduardo Pelegrillopart (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: