Skip to content

Commit d9df267

Browse files
committed
Custom transformations should throw on main thread.
1 parent 5afb484 commit d9df267

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

picasso/src/main/java/com/squareup/picasso/BitmapHunter.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ static void calculateInSampleSize(int reqWidth, int reqHeight, BitmapFactory.Opt
221221

222222
static Bitmap applyCustomTransformations(List<Transformation> transformations, Bitmap result) {
223223
for (int i = 0, count = transformations.size(); i < count; i++) {
224-
Transformation transformation = transformations.get(i);
224+
final Transformation transformation = transformations.get(i);
225225
Bitmap newResult = transformation.transform(result);
226226

227227
if (newResult == null) {
228-
StringBuilder builder = new StringBuilder() //
228+
final StringBuilder builder = new StringBuilder() //
229229
.append("Transformation ")
230230
.append(transformation.key())
231231
.append(" returned null after ")
@@ -234,20 +234,36 @@ static Bitmap applyCustomTransformations(List<Transformation> transformations, B
234234
for (Transformation t : transformations) {
235235
builder.append(t.key()).append('\n');
236236
}
237-
throw new NullPointerException(builder.toString());
237+
Picasso.HANDLER.post(new Runnable() {
238+
@Override public void run() {
239+
throw new NullPointerException(builder.toString());
240+
}
241+
});
242+
return null;
238243
}
239244

240245
if (newResult == result && result.isRecycled()) {
241-
throw new IllegalStateException(
242-
"Transformation " + transformation.key() + " returned input Bitmap but recycled it.");
246+
Picasso.HANDLER.post(new Runnable() {
247+
@Override public void run() {
248+
throw new IllegalStateException(
249+
"Transformation " + transformation.key() + " returned input Bitmap but recycled it.");
250+
}
251+
});
252+
return null;
243253
}
244254

245255
// If the transformation returned a new bitmap ensure they recycled the original.
246256
if (newResult != result && !result.isRecycled()) {
247-
throw new IllegalStateException("Transformation "
248-
+ transformation.key()
249-
+ " mutated input Bitmap but failed to recycle the original.");
257+
Picasso.HANDLER.post(new Runnable() {
258+
@Override public void run() {
259+
throw new IllegalStateException("Transformation "
260+
+ transformation.key()
261+
+ " mutated input Bitmap but failed to recycle the original.");
262+
}
263+
});
264+
return null;
250265
}
266+
251267
result = newResult;
252268
}
253269
return result;

picasso/src/test/java/com/squareup/picasso/BitmapHunterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public class BitmapHunterTest {
405405
assertThat(shadowMatrix.getPreOperations()).containsOnly("scale 0.5 0.5");
406406
}
407407

408-
@Test public void reusedBitmapIsNotRecycled() {
408+
@Test public void reusedBitmapIsNotRecycled() throws Exception {
409409
Request data = new Request.Builder(URI_1).build();
410410
Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
411411
Bitmap result = transformResult(data, source, 0);

0 commit comments

Comments
 (0)