I traced this down to Envjs.connection (env.js#1631) being
executed after an
exception was not handled properly. If the else (#1614) branch was
taken, the
outstream and buffer are of type Writer, but the instream (#1628)
is of type
InputStream.
1605: try{
1606: //console.log('contentEncoding %s', contentEncoding);
1607: if( contentEncoding.equalsIgnoreCase("gzip") ||
1608: contentEncoding.equalsIgnoreCase("decompress")){
1609: //zipped content
1610: binary = true;
1611: outstream = new java.io.ByteArrayOutputStream();
1612: buffer =
java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);
1613: instream = new
java.util.zip.GZIPInputStream(connection.getInputStream())
1614: }else{
1615: //this is a text file
1616: outstream = new java.io.StringWriter();
1617 buffer =
java.lang.reflect.Array.newInstance(java.lang.Character.TYPE,
1024);
1618: instream = new
java.io.InputStreamReader(connection.getInputStream());
1619: }
1620: }catch(e){
1621: if (connection.getResponseCode() == 404){
1622: console.log('failed to open connection stream \n %s %s',
1623: e.toString(), e);
1624: }else{
1625: console.log('failed to open connection stream \n %s %s',
1626: e.toString(), e);
1627: }
1628: instream = connection.getErrorStream();
1629: }
1630:
1631: while ((length = instream.read(buffer, 0, 1024)) != -1) {
1632: outstream.write(buffer, 0, length);
1633: }
The fix is to insert these after #1628:
1628: instream = connection.getErrorStream();
if (!binary) {
outstream = new java.io.ByteArrayOutputStream();
buffer =
java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE,
1024);
}
1629: }