471985 NPE in HttpFields.putField

The problem had several aspects:
 * HttpField.add should not let a null entry be added to the fields
 * The putHeaders methods should have checked for a null field before trying to add it
 * But the fundamental problem was the JarFileResource.close was leaving exist==true, so a new entry was never created.
This commit is contained in:
Greg Wilkins 2015-07-08 16:04:43 +10:00
parent 8c72d04415
commit 7fbf512b17
2 changed files with 8 additions and 6 deletions

View File

@ -682,9 +682,12 @@ public class HttpFields implements Iterable<HttpField>
public void add(HttpField field)
{
if (_size==_fields.length)
_fields=Arrays.copyOf(_fields,_size*2);
_fields[_size++]=field;
if (field!=null)
{
if (_size==_fields.length)
_fields=Arrays.copyOf(_fields,_size*2);
_fields[_size++]=field;
}
}
public void addAll(HttpFields fields)

View File

@ -55,13 +55,13 @@ class JarFileResource extends JarResource
protected JarFileResource(URL url, boolean useCaches)
{
super(url, useCaches);
}
}
/* ------------------------------------------------------------ */
@Override
public synchronized void close()
{
_exists=false;
_list=null;
_entry=null;
_file=null;
@ -144,7 +144,6 @@ class JarFileResource extends JarResource
if (_urlString.endsWith("!/"))
{
String file_url=_urlString.substring(4,_urlString.length()-2);
try{return newResource(file_url).exists();}
catch(Exception e) {LOG.ignore(e); return false;}