Issue #4860 NPE from HttpFields
+ Fix bug with list iterator nextIndex + List iterator cannot inject null fields + minor cleanups Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
parent
6af6af6419
commit
1ac7fe4f9c
|
@ -303,14 +303,18 @@ public class HttpFields implements Iterable<HttpField>
|
|||
*/
|
||||
public List<String> getValuesList(String name)
|
||||
{
|
||||
final List<String> list = new ArrayList<>();
|
||||
List<String> list = null;
|
||||
for (int i = 0; i < _size; i++)
|
||||
{
|
||||
HttpField f = _fields[i];
|
||||
if (f.getName().equalsIgnoreCase(name))
|
||||
{
|
||||
if (list == null)
|
||||
list = new ArrayList<>(size() - i);
|
||||
list.add(f.getValue());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return list == null ? Collections.emptyList() : list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -711,7 +715,8 @@ public class HttpFields implements Iterable<HttpField>
|
|||
|
||||
public void add(HttpHeader header, HttpHeaderValue value)
|
||||
{
|
||||
add(header, value.toString());
|
||||
if (value != null)
|
||||
add(header, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -966,8 +971,11 @@ public class HttpFields implements Iterable<HttpField>
|
|||
*
|
||||
* @param fields the fields to add
|
||||
*/
|
||||
@Deprecated
|
||||
public void add(HttpFields fields)
|
||||
{
|
||||
// TODO this implementation doesn't do what the javadoc says and is really the same
|
||||
// as addAll, which is renamed to add anyway in 10.
|
||||
if (fields == null)
|
||||
return;
|
||||
|
||||
|
@ -1185,7 +1193,7 @@ public class HttpFields implements Iterable<HttpField>
|
|||
@Override
|
||||
public int nextIndex()
|
||||
{
|
||||
return _cursor + 1;
|
||||
return _cursor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1199,16 +1207,22 @@ public class HttpFields implements Iterable<HttpField>
|
|||
{
|
||||
if (_current < 0)
|
||||
throw new IllegalStateException();
|
||||
_fields[_current] = field;
|
||||
if (field == null)
|
||||
remove();
|
||||
else
|
||||
_fields[_current] = field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(HttpField field)
|
||||
{
|
||||
_fields = Arrays.copyOf(_fields, _fields.length + 1);
|
||||
System.arraycopy(_fields, _cursor, _fields, _cursor + 1, _size++);
|
||||
_fields[_cursor++] = field;
|
||||
_current = -1;
|
||||
if (field != null)
|
||||
{
|
||||
_fields = Arrays.copyOf(_fields, _fields.length + 1);
|
||||
System.arraycopy(_fields, _cursor, _fields, _cursor + 1, _size++);
|
||||
_fields[_cursor++] = field;
|
||||
_current = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue