You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@abdera.apache.org by "Antoine Toulme (JIRA)" <ji...@apache.org> on 2011/01/10 19:29:51 UTC

[jira] Created: (ABDERA-279) Faulty classloading - unreachable code

Faulty classloading - unreachable code
--------------------------------------

                 Key: ABDERA-279
                 URL: https://issues.apache.org/jira/browse/ABDERA-279
             Project: Abdera
          Issue Type: Bug
    Affects Versions: 1.1.1
            Reporter: Antoine Toulme


The Discover class uses this method to get a class:

{code}
      private static <T> Class<T> getClass(ClassLoader loader, String spec) {
        Class<T> c = null;
        try {
            c = (Class<T>)loader.loadClass(spec);
            c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        return c;
    }
{code}

However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
{code}
c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
{code}


The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ABDERA-279) Faulty classloading - unreachable code

Posted by "ant elder (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ABDERA-279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12981671#action_12981671 ] 

ant elder commented on ABDERA-279:
----------------------------------

Patch applied, thanks for the fix Antoine.

Tests would be good but as the class has no other testing already it seems ok to not require them for others.

I needed to get the 1.1.2 release out for a fix for another user and as it was already being voted on it would have delayed it to long to include this. I can do a 1.1.3 release to include this fix now if you need it ASAP.

> Faulty classloading - unreachable code
> --------------------------------------
>
>                 Key: ABDERA-279
>                 URL: https://issues.apache.org/jira/browse/ABDERA-279
>             Project: Abdera
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: Antoine Toulme
>         Attachments: fix_classloader.patch
>
>
> The Discover class uses this method to get a class:
> {code}
>       private static <T> Class<T> getClass(ClassLoader loader, String spec) {
>         Class<T> c = null;
>         try {
>             c = (Class<T>)loader.loadClass(spec);
>             c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
>         } catch (ClassNotFoundException e) {
>             throw new RuntimeException(e);
>         }
>         return c;
>     }
> {code}
> However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
> {code}
> c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
> {code}
> The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ABDERA-279) Faulty classloading - unreachable code

Posted by "Christine Koppelt (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ABDERA-279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12980321#action_12980321 ] 

Christine Koppelt commented on ABDERA-279:
------------------------------------------

Would be great if you could also add some tests for your patch.

> Faulty classloading - unreachable code
> --------------------------------------
>
>                 Key: ABDERA-279
>                 URL: https://issues.apache.org/jira/browse/ABDERA-279
>             Project: Abdera
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: Antoine Toulme
>         Attachments: fix_classloader.patch
>
>
> The Discover class uses this method to get a class:
> {code}
>       private static <T> Class<T> getClass(ClassLoader loader, String spec) {
>         Class<T> c = null;
>         try {
>             c = (Class<T>)loader.loadClass(spec);
>             c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
>         } catch (ClassNotFoundException e) {
>             throw new RuntimeException(e);
>         }
>         return c;
>     }
> {code}
> However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
> {code}
> c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
> {code}
> The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ABDERA-279) Faulty classloading - unreachable code

Posted by "Antoine Toulme (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ABDERA-279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12980417#action_12980417 ] 

Antoine Toulme commented on ABDERA-279:
---------------------------------------

Christine, where should I place those tests ? Where should I start ? It doesn't like there are tests for this class at all and the method is private static, which makes it difficult to test.

> Faulty classloading - unreachable code
> --------------------------------------
>
>                 Key: ABDERA-279
>                 URL: https://issues.apache.org/jira/browse/ABDERA-279
>             Project: Abdera
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: Antoine Toulme
>         Attachments: fix_classloader.patch
>
>
> The Discover class uses this method to get a class:
> {code}
>       private static <T> Class<T> getClass(ClassLoader loader, String spec) {
>         Class<T> c = null;
>         try {
>             c = (Class<T>)loader.loadClass(spec);
>             c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
>         } catch (ClassNotFoundException e) {
>             throw new RuntimeException(e);
>         }
>         return c;
>     }
> {code}
> However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
> {code}
> c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
> {code}
> The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ABDERA-279) Faulty classloading - unreachable code

Posted by "ant elder (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ABDERA-279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12979694#action_12979694 ] 

ant elder commented on ABDERA-279:
----------------------------------

Thanks Antoine, that does look wrong. Any chance you would provide a fix patch? 

> Faulty classloading - unreachable code
> --------------------------------------
>
>                 Key: ABDERA-279
>                 URL: https://issues.apache.org/jira/browse/ABDERA-279
>             Project: Abdera
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: Antoine Toulme
>
> The Discover class uses this method to get a class:
> {code}
>       private static <T> Class<T> getClass(ClassLoader loader, String spec) {
>         Class<T> c = null;
>         try {
>             c = (Class<T>)loader.loadClass(spec);
>             c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
>         } catch (ClassNotFoundException e) {
>             throw new RuntimeException(e);
>         }
>         return c;
>     }
> {code}
> However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
> {code}
> c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
> {code}
> The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (ABDERA-279) Faulty classloading - unreachable code

Posted by "Antoine Toulme (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/ABDERA-279?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Antoine Toulme updated ABDERA-279:
----------------------------------

    Attachment: fix_classloader.patch

Patch attached, I ran the tests and they all passed.

> Faulty classloading - unreachable code
> --------------------------------------
>
>                 Key: ABDERA-279
>                 URL: https://issues.apache.org/jira/browse/ABDERA-279
>             Project: Abdera
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: Antoine Toulme
>         Attachments: fix_classloader.patch
>
>
> The Discover class uses this method to get a class:
> {code}
>       private static <T> Class<T> getClass(ClassLoader loader, String spec) {
>         Class<T> c = null;
>         try {
>             c = (Class<T>)loader.loadClass(spec);
>             c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
>         } catch (ClassNotFoundException e) {
>             throw new RuntimeException(e);
>         }
>         return c;
>     }
> {code}
> However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
> {code}
> c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
> {code}
> The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ABDERA-279) Faulty classloading - unreachable code

Posted by "Antoine Toulme (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ABDERA-279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12979701#action_12979701 ] 

Antoine Toulme commented on ABDERA-279:
---------------------------------------

Can you delay 1.1.2 till I provide one ? It should be a matter of an hour but I can't contribute it before tonight/tomorrow night timeframe.

> Faulty classloading - unreachable code
> --------------------------------------
>
>                 Key: ABDERA-279
>                 URL: https://issues.apache.org/jira/browse/ABDERA-279
>             Project: Abdera
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: Antoine Toulme
>
> The Discover class uses this method to get a class:
> {code}
>       private static <T> Class<T> getClass(ClassLoader loader, String spec) {
>         Class<T> c = null;
>         try {
>             c = (Class<T>)loader.loadClass(spec);
>             c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
>         } catch (ClassNotFoundException e) {
>             throw new RuntimeException(e);
>         }
>         return c;
>     }
> {code}
> However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
> {code}
> c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
> {code}
> The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (ABDERA-279) Faulty classloading - unreachable code

Posted by "Antoine Toulme (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/ABDERA-279?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12981679#action_12981679 ] 

Antoine Toulme commented on ABDERA-279:
---------------------------------------

Thanks! I already patched my way out of this on my side, so no need for a release I think.

> Faulty classloading - unreachable code
> --------------------------------------
>
>                 Key: ABDERA-279
>                 URL: https://issues.apache.org/jira/browse/ABDERA-279
>             Project: Abdera
>          Issue Type: Bug
>    Affects Versions: 1.1.1
>            Reporter: Antoine Toulme
>         Attachments: fix_classloader.patch
>
>
> The Discover class uses this method to get a class:
> {code}
>       private static <T> Class<T> getClass(ClassLoader loader, String spec) {
>         Class<T> c = null;
>         try {
>             c = (Class<T>)loader.loadClass(spec);
>             c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
>         } catch (ClassNotFoundException e) {
>             throw new RuntimeException(e);
>         }
>         return c;
>     }
> {code}
> However the first line inside the try statement will throw a CNF exception if the class cannot be found. As a result, the second line is never executed.
> {code}
> c = (Class<T>)(c != null ? c : getClass(Discover.class.getClassLoader(), spec));
> {code}
> The code executes recursively, which makes things harder. I would recommend changing the way the code is currently written to avoid recursion.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.