aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/lang/natString.cc25
1 files changed, 23 insertions, 2 deletions
diff --git a/libjava/java/lang/natString.cc b/libjava/java/lang/natString.cc
index f177c23..75006a7 100644
--- a/libjava/java/lang/natString.cc
+++ b/libjava/java/lang/natString.cc
@@ -1,6 +1,7 @@
// natString.cc - Implementation of java.lang.String native methods.
-/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008 Free Software Foundation
This file is part of libgcj.
@@ -23,6 +24,7 @@ details. */
#include <java/lang/NullPointerException.h>
#include <java/lang/StringBuffer.h>
#include <java/io/ByteArrayOutputStream.h>
+#include <java/io/CharConversionException.h>
#include <java/io/OutputStreamWriter.h>
#include <java/io/ByteArrayInputStream.h>
#include <java/io/InputStreamReader.h>
@@ -493,9 +495,28 @@ java::lang::String::init (jbyteArray bytes, jint offset, jint count,
converter->setInput(bytes, offset, offset+count);
while (converter->inpos < converter->inlength)
{
- int done = converter->read(array, outpos, avail);
+ int done;
+ try
+ {
+ done = converter->read(array, outpos, avail);
+ }
+ catch (::java::io::CharConversionException *e)
+ {
+ // Ignore it and silently throw away the offending data.
+ break;
+ }
if (done == 0)
{
+ // done is zero if either there is no space available in the
+ // output *or* the input is incomplete. We assume that if
+ // there are 20 characters available in the output, the
+ // input must be incomplete and there is no more work to do.
+ // This means we may skip several bytes of input, but that
+ // is OK as the behavior is explicitly unspecified in this
+ // case.
+ if (avail - outpos > 20)
+ break;
+
jint new_size = 2 * (outpos + avail);
jcharArray new_array = JvNewCharArray (new_size);
memcpy (elements (new_array), elements (array),