ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bas Nossing (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (IVY-1452) NullPointerException when accessing charset to invalid URL
Date Tue, 02 Sep 2014 12:52:21 GMT

    [ https://issues.apache.org/jira/browse/IVY-1452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14118152#comment-14118152
] 

Bas Nossing edited comment on IVY-1452 at 9/2/14 12:51 PM:
-----------------------------------------------------------

Timothy's fix works for me. here's the patch:

{noformat}
Index: src/java/org/apache/ivy/util/url/ApacheURLLister.java
===================================================================
--- src/java/org/apache/ivy/util/url/ApacheURLLister.java	(revision 1621956)
+++ src/java/org/apache/ivy/util/url/ApacheURLLister.java	(working copy)
@@ -29,6 +29,7 @@
 
 import org.apache.ivy.util.FileUtil;
 import org.apache.ivy.util.Message;
+import org.apache.ivy.util.url.URLHandler.URLInfo;
 
 /**
  * Utility class which helps to list urls under a given url. This has been tested with Apache
1.3.33
@@ -108,7 +109,13 @@
         }
 
         URLHandler urlHandler = URLHandlerRegistry.getDefault();
-        String charset = urlHandler.getURLInfo(url).getBodyCharset();
+        URLInfo urlInfo = urlHandler.getURLInfo(url);
+        if (urlInfo == URLHandler.UNAVAILABLE) {
+            return urlList; // not found => return empty list
+        }
+        // here, urlInfo is valid
+        String charset = urlInfo.getBodyCharset();
+
         InputStream contentStream = urlHandler.openStream(url);
         BufferedReader r = new BufferedReader(new InputStreamReader(contentStream, charset));
{noformat}


was (Author: b.nossing):
Timothy's fix works for me. here's the patch:

Index: src/java/org/apache/ivy/util/url/ApacheURLLister.java
===================================================================
--- src/java/org/apache/ivy/util/url/ApacheURLLister.java	(revision 1621956)
+++ src/java/org/apache/ivy/util/url/ApacheURLLister.java	(working copy)
@@ -29,6 +29,7 @@
 
 import org.apache.ivy.util.FileUtil;
 import org.apache.ivy.util.Message;
+import org.apache.ivy.util.url.URLHandler.URLInfo;
 
 /**
  * Utility class which helps to list urls under a given url. This has been tested with Apache
1.3.33
@@ -108,7 +109,13 @@
         }
 
         URLHandler urlHandler = URLHandlerRegistry.getDefault();
-        String charset = urlHandler.getURLInfo(url).getBodyCharset();
+        URLInfo urlInfo = urlHandler.getURLInfo(url);
+        if (urlInfo == URLHandler.UNAVAILABLE) {
+            return urlList; // not found => return empty list
+        }
+        // here, urlInfo is valid
+        String charset = urlInfo.getBodyCharset();
+
         InputStream contentStream = urlHandler.openStream(url);
         BufferedReader r = new BufferedReader(new InputStreamReader(contentStream, charset));
 

> NullPointerException when accessing charset to invalid URL
> ----------------------------------------------------------
>
>                 Key: IVY-1452
>                 URL: https://issues.apache.org/jira/browse/IVY-1452
>             Project: Ivy
>          Issue Type: Bug
>    Affects Versions: 2.4.0
>         Environment: windows 7
>            Reporter: Frédéric RIVIERE
>            Priority: Blocker
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Trace is:
> java.lang.NullPointerException: charsetName
>   at java.io.InputStreamReader.<init>(Unknown Source)
>   at org.apache.ivy.util.url.ApacheURLLister.retrieveListing(ApacheURLLister.java:113)
>   at org.apache.ivy.util.url.ApacheURLLister.listAll(ApacheURLLister.java:57)
>   at org.apache.ivy.plugins.repository.url.URLRepository.list(URLRepository.java:100)
>   at org.apache.ivy.plugins.resolver.util.ResolverHelper.listAll(ResolverHelper.java:105)
>   at org.apache.ivy.plugins.resolver.util.ResolverHelper.listTokenValues(ResolverHelper.java:57)
>   at org.apache.ivy.plugins.resolver.util.ResolverHelper.findAll(ResolverHelper.java:139)
>   at org.apache.ivy.plugins.resolver.RepositoryResolver.listResources(RepositoryResolver.java:185)
>   at org.apache.ivy.plugins.resolver.RepositoryResolver.findDynamicResourceUsingPattern(RepositoryResolver.java:149)
>   at org.apache.ivy.plugins.resolver.RepositoryResolver.findResourceUsingPattern(RepositoryResolver.java:132)
>   at org.apache.ivy.plugins.resolver.AbstractPatternsBasedResolver.findResourceUsingPatterns(AbstractPatternsBasedResolver.java:96)
>   at org.apache.ivy.plugins.resolver.AbstractPatternsBasedResolver.findArtifactRef(AbstractPatternsBasedResolver.java:75)
>   at org.apache.ivy.plugins.resolver.BasicResolver.getArtifactRef(BasicResolver.java:1034)
>   at org.apache.ivy.plugins.resolver.BasicResolver.findFirstArtifactRef(BasicResolver.java:971)
>   at org.apache.ivy.plugins.resolver.BasicResolver.getDependency(BasicResolver.java:243)
>   at org.apache.ivy.plugins.resolver.ChainResolver.getDependency(ChainResolver.java:104)
>   at org.apache.ivy.plugins.resolver.ChainResolver.getDependency(ChainResolver.java:104)
>   at org.apache.ivy.core.resolve.IvyNode.loadData(IvyNode.java:169)
>   at org.apache.ivy.core.resolve.VisitNode.loadData(VisitNode.java:292)
>   at org.apache.ivy.core.resolve.ResolveEngine.fetchDependencies(ResolveEngine.java:717)
>   at org.apache.ivy.core.resolve.ResolveEngine.doFetchDependencies(ResolveEngine.java:802)
>   at org.apache.ivy.core.resolve.ResolveEngine.fetchDependencies(ResolveEngine.java:725)
>   at org.apache.ivy.core.resolve.ResolveEngine.getDependencies(ResolveEngine.java:597)
>   at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:234)
>   at org.apache.ivy.core.resolve.ResolveEngine.resolve(ResolveEngine.java:195)
>   at org.apache.ivy.Ivy.resolve(Ivy.java:507)
>   at org.apache.ivy.ant.IvyResolve.doExecute(IvyResolve.java:337)
>   at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:273)
>   at org.apache.ivy.ant.IvyPostResolveTask.ensureResolved(IvyPostResolveTask.java:241)
>   at org.apache.ivy.ant.IvyPostResolveTask.prepareAndCheck(IvyPostResolveTask.java:188)
>   at org.apache.ivy.ant.IvyRetrieve.doExecute(IvyRetrieve.java:89)
>   at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:273)
>   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
>   at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
>   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>   at java.lang.reflect.Method.invoke(Unknown Source)
>   at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
>   at org.apache.tools.ant.Task.perform(Task.java:348)
>   at org.apache.tools.ant.Target.execute(Target.java:392)
>   at org.apache.tools.ant.Target.performTasks(Target.java:413)
>   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
>   at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
>   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>   at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
>   at org.apache.tools.ant.Main.runBuild(Main.java:811)
>   at org.apache.tools.ant.Main.startAnt(Main.java:217)
>   at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
>   at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
> After investigations, a check is missing in in class org.apache.ivy.util.url.ApacheURLLister,
in method 
> List retrieveListing(URL,boolean,boolean) :
> [...]
> String charset = urlHandler.getURLInfo(url).getBodyCharset();
> [...]
> According to spec of urlHandler.getURLInfo(url), it may return URLHandler.UNAVAILABLE.
> I have replace the above line by the following and it works fine:
> [...]
> URLInfo urlInfo = urlHandler.getURLInfo(url);
> if(urlInfo == URLHandler.UNAVAILABLE)
>       	return urlList; // not found => return empty list
> // here, urlInfo is valid
> String charset = urlInfo.getBodyCharset();
> [...]
> This is blocking for us. Is there a chance to integrate it soon ?
> Otherwise, I will need to build my own patched jar.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message