Qpid
  1. Qpid
  2. QPID-3395

Parsing exception of JNDI file should not be swallowed in Java library

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.10
    • Fix Version/s: 0.14
    • Component/s: Java Client
    • Labels:
      None

      Description

      Description of problem:
      When JNDI file has a typo, InitialContext(properties) method should raise some
      parsing exception to let client program know about the parsing problem.
      Currently the exception is swallowed in
      PropertiesFileInitialContextFactory.createDestination method, writing to stdout
      the exception stack trace only.

      How reproducible:
      100%

      Steps to Reproduce:
      1. Run the attached program with the attached MRG.jms.properties
      2. In the output, distinguish between stdout and stderr

      Actual results:
      stdout contains:
      WARN [main] (PropertiesFileInitialContextFactory.java:244) - Unable to create
      destination:org.apache.qpid.messaging.util.ParseError: expecting LBRACE, got
      EOF line:1,7:queue2;
      org.apache.qpid.messaging.util.ParseError: expecting LBRACE, got EOF
      line:1,7:queue2;
      at org.apache.qpid.messaging.util.Parser.eat(Parser.java:65)
      at org.apache.qpid.messaging.util.AddressParser.map(AddressParser.java:282)
      at
      org.apache.qpid.messaging.util.AddressParser.address(AddressParser.java:270)
      at org.apache.qpid.messaging.util.AddressParser.parse(AddressParser.java:241)
      at org.apache.qpid.messaging.Address.parse(Address.java:40)
      at
      org.apache.qpid.client.AMQDestination.createAddressFromString(AMQDestination.java:855)
      at
      org.apache.qpid.client.AMQDestination.createDestination(AMQDestination.java:696)
      at
      org.apache.qpid.jndi.PropertiesFileInitialContextFactory.createDestination(PropertiesFileInitialContextFactory.java:240)
      at
      org.apache.qpid.jndi.PropertiesFileInitialContextFactory.createDestinations(PropertiesFileInitialContextFactory.java:160)
      at
      org.apache.qpid.jndi.PropertiesFileInitialContextFactory.getInitialContext(PropertiesFileInitialContextFactory.java:117)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
      at javax.naming.InitialContext.init(InitialContext.java:223)
      at javax.naming.InitialContext.<init>(InitialContext.java:197)
      at JNDIError.runTest(JNDIError.java:19)
      at JNDIError.main(JNDIError.java:12)

      stderr contains:
      javax.naming.NameNotFoundException: my-queue
      at org.apache.qpid.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:271)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at JNDIError.runTest(JNDIError.java:20)
      at JNDIError.main(JNDIError.java:12)

      Expected results:
      program execution is interrupted by (laterly caught exception) even on
      line:
      Context context = new InitialContext(properties);
      due to parsing error
      stderr contains the org.apache.qpid.messaging.util.ParseError exception,
      not javax.naming.NameNotFoundException

      Additional info:
      The requirement makes sense as now only some error log is printed to stdout
      (not catch-able by the Java client program). While the API should warn the
      application directly using catch-able exception that the parsing went wrong
      (and some destination / topic / whatever can't be used in the program later
      on).

      1. parseexception.patch
        3 kB
        Pavel Moravec
      2. JIRA3395_reproduction.tar.gz
        1 kB
        Pavel Moravec

        Activity

        Hide
        Pavel Moravec added a comment -

        Stuff for reproduction

        Show
        Pavel Moravec added a comment - Stuff for reproduction
        Hide
        Pavel Moravec added a comment -

        Patch proposal - an internal parsing exception caught in createDestination and createFactory method is re-thrown as NamingException (the only exception type that can be thrown by getInitialContext method).

        Show
        Pavel Moravec added a comment - Patch proposal - an internal parsing exception caught in createDestination and createFactory method is re-thrown as NamingException (the only exception type that can be thrown by getInitialContext method).
        Hide
        Pavel Moravec added a comment -

        Improved patch proposal to re-throw also parse error in initial context URL.

        Internal exceptions in PropertiesFileInitialContex.createFactory and PropertiesFileInitialContex.createDestination are re-thrown as ConfigurationException with sting "Failed to parse JNDI properties file: "+e.getMessage().

        Show
        Pavel Moravec added a comment - Improved patch proposal to re-throw also parse error in initial context URL. Internal exceptions in PropertiesFileInitialContex.createFactory and PropertiesFileInitialContex.createDestination are re-thrown as ConfigurationException with sting "Failed to parse JNDI properties file: "+e.getMessage().
        Hide
        Rajith Attapattu added a comment -

        Applied Pavel's patch with minor modifications.
        Verified the fix by testing manually.
        Didn't add an automated test for the moment.

        Show
        Rajith Attapattu added a comment - Applied Pavel's patch with minor modifications. Verified the fix by testing manually. Didn't add an automated test for the moment.

          People

          • Assignee:
            Rajith Attapattu
            Reporter:
            Pavel Moravec
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development