ICEpdf
  1. ICEpdf
  2. PDF-25

Stackoverflow bug found on Defs.property when running as applet

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 3.0
    • Fix Version/s: 4.3
    • Component/s: None
    • Labels:
      None
    • Environment:
      JDK 1.6u7, Windows XP SP2, IExplorer 8 or FireFox 3.x

      Description

      Hi! I am evaluating IcePdf to use it for an applet that will print the PDF referenced by an URL, but it does not work, and I get this error:

      Code:

       java.lang.StackOverflowError
        at java.lang.ref.ReferenceQueue.poll(Unknown Source)
        at java.util.WeakHashMap.expungeStaleEntries(Unknown Source)
        at java.util.WeakHashMap.getTable(Unknown Source)
        at java.util.WeakHashMap.get(Unknown Source)
        at java.util.Collections$SynchronizedMap.get(Unknown Source)
        at sun.security.provider.PolicyFile.implies(Unknown Source)
        at java.security.ProtectionDomain.implies(Unknown Source)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
        at java.lang.System.getProperty(Unknown Source)
        at org.icepdf.core.util.Defs.property(Unknown Source)
        at org.icepdf.core.util.Defs.property(Unknown Source)
        at org.icepdf.core.util.Defs.property(Unknown Source)
       



      The problem seems to be at org.icepdf.core.util.Defs.property:

      Code:

       
       public static String property(String paramString1, String paramString2)
         {
           try
           {
             return System.getProperty(paramString1, paramString2);
           }
           catch (SecurityException localSecurityException)
           {
             property(paramString1, paramString2);
           }
           return paramString2;
         }
       
       
      If a SecurityException is produced, the catch will recursively call the property "ad infinitum" an eventually that will cause an StackOverflowError, what it should do is present me with the error message of the SecurityException.

        Activity

        Hide
        Patrick Corless added a comment -

        This issue was addressed for 4.3.0.

        Show
        Patrick Corless added a comment - This issue was addressed for 4.3.0.
        Hide
        Patrick Corless added a comment -

        Hi Francisco, thanks for the bug reports. I'll update the code in question to avoid the stack overflow error which is always a bad thing.

        The applet Sandbox only allows for a few system properties to be read, do you know which properties are being set to cause the call in the first place? Here is a rather dated article on the specifics of the applet sandbox, http://www.hell.org.ua/Docs/oreilly/javaenterprise/jnut/ch05_04.htm .

        Show
        Patrick Corless added a comment - Hi Francisco, thanks for the bug reports. I'll update the code in question to avoid the stack overflow error which is always a bad thing. The applet Sandbox only allows for a few system properties to be read, do you know which properties are being set to cause the call in the first place? Here is a rather dated article on the specifics of the applet sandbox, http://www.hell.org.ua/Docs/oreilly/javaenterprise/jnut/ch05_04.htm .
        Hide
        Francisco Peredo added a comment -

        I now think this might be a better solution:

        public static String property(String name, String defaultValue) {
        try

        { return System.getProperty(name, defaultValue); }

        catch (SecurityException ex)

        { logger.log(Level.FINE, "Failed to obtain property.", ex); }


        return defaultValue;
        }

        This way the applet does not crash, the securityException message is preserved, and the default value is returned (and an StackOverflow is not produced)

        Show
        Francisco Peredo added a comment - I now think this might be a better solution: public static String property(String name, String defaultValue) { try { return System.getProperty(name, defaultValue); } catch (SecurityException ex) { logger.log(Level.FINE, "Failed to obtain property.", ex); } return defaultValue; } This way the applet does not crash, the securityException message is preserved, and the default value is returned (and an StackOverflow is not produced)
        Hide
        Francisco Peredo added a comment -

        Just submited PDF-26, a very similar problem but with setProperty

        Show
        Francisco Peredo added a comment - Just submited PDF-26 , a very similar problem but with setProperty
        Hide
        Francisco Peredo added a comment -

        The solution is (AFAIK) very simple:

        Code:

        public static String property(String paramString1, String paramString2)
        {
        try

        { return System.getProperty(paramString1, paramString2); }

        catch (SecurityException localSecurityException)

        { throw new RuntimeException(localSecurityException.getMessage(),localSecurityException); }

        return paramString2;
        }

        Show
        Francisco Peredo added a comment - The solution is (AFAIK) very simple: Code: public static String property(String paramString1, String paramString2) { try { return System.getProperty(paramString1, paramString2); } catch (SecurityException localSecurityException) { throw new RuntimeException(localSecurityException.getMessage(),localSecurityException); } return paramString2; }

          People

          • Assignee:
            Patrick Corless
            Reporter:
            Francisco Peredo
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: