AndroidTileBitmap(InputStream inputStream, int tileSize, boolean isTransparent) { super(); try { if (AndroidGraphicFactory.DEBUG_BITMAPS) { tileInstances.incrementAndGet(); } this.bitmap = BitmapFactory.decodeStream(inputStream, null, createTileBitmapFactoryOptions(tileSize, isTransparent)); // somehow on Android the decode stream can succeed, but the bitmap remains invalid. // Asking for the width forces the bitmap to be fully loaded and a NullPointerException // is triggered if the stream is not readable, // so that it can be handled at this point, rather than later // during bitmap painting this.bitmap.getWidth(); //NOSONAR } catch (Exception e) { // this is really stupid, the runtime system actually throws a SocketTimeoutException, // but we cannot catch it, because it is not declared, so we needed to catch the base // class exception LOGGER.info("TILEBITMAP ERROR " + e.toString()); this.bitmap = null; // need to null out to avoid recycling IOUtils.closeQuietly(inputStream); // seems to improve memory usage this.destroy(); throw new CorruptedInputStreamException("Corrupted bitmap input stream", e); } }