The following issues were found

picasso/src/oldTests/java/com/squareup/picasso3/BitmapTargetActionTest.java
13 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 58

                  BitmapTargetAction request =
        new BitmapTargetAction(mock(Picasso.class), target, null, null, 0);
    request.complete(new RequestHandler.Result(bitmap, MEMORY));
    verify(target).onBitmapLoaded(bitmap, MEMORY);
  }

  @Test
  public void invokesOnBitmapFailedIfTargetIsNotNullWithErrorDrawable() {
    Drawable errorDrawable = mock(Drawable.class);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 70

              
    request.error(e);

    verify(target).onBitmapFailed(e, errorDrawable);
  }

  @Test
  public void invokesOnBitmapFailedIfTargetIsNotNullWithErrorResourceId() {
    Drawable errorDrawable = mock(Drawable.class);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 86

                  Resources res = mock(Resources.class);
    BitmapTargetAction request = new BitmapTargetAction(picasso, target, null, null, RESOURCE_ID_1);

    when(context.getResources()).thenReturn(res);
    when(res.getDrawable(RESOURCE_ID_1)).thenReturn(errorDrawable);
    Exception e = new RuntimeException();

    request.error(e);


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 86

                  Resources res = mock(Resources.class);
    BitmapTargetAction request = new BitmapTargetAction(picasso, target, null, null, RESOURCE_ID_1);

    when(context.getResources()).thenReturn(res);
    when(res.getDrawable(RESOURCE_ID_1)).thenReturn(errorDrawable);
    Exception e = new RuntimeException();

    request.error(e);


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 87

                  BitmapTargetAction request = new BitmapTargetAction(picasso, target, null, null, RESOURCE_ID_1);

    when(context.getResources()).thenReturn(res);
    when(res.getDrawable(RESOURCE_ID_1)).thenReturn(errorDrawable);
    Exception e = new RuntimeException();

    request.error(e);

    verify(target).onBitmapFailed(e, errorDrawable);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 87

                  BitmapTargetAction request = new BitmapTargetAction(picasso, target, null, null, RESOURCE_ID_1);

    when(context.getResources()).thenReturn(res);
    when(res.getDrawable(RESOURCE_ID_1)).thenReturn(errorDrawable);
    Exception e = new RuntimeException();

    request.error(e);

    verify(target).onBitmapFailed(e, errorDrawable);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 92

              
    request.error(e);

    verify(target).onBitmapFailed(e, errorDrawable);
  }

  @Test public void recyclingInSuccessThrowsException() {
    BitmapTarget bad = new BitmapTarget() {
      @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {

            

Reported by PMD.

In JUnit4, use the @Test(expected) annotation to denote tests that should throw exceptions
Design

Line: 114

                  BitmapTargetAction tr = new BitmapTargetAction(picasso, bad, null, null, 0);
    try {
      tr.complete(new RequestHandler.Result(bitmap, MEMORY));
      fail();
    } catch (IllegalStateException ignored) {
    }
  }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 114

                  BitmapTargetAction tr = new BitmapTargetAction(picasso, bad, null, null, 0);
    try {
      tr.complete(new RequestHandler.Result(bitmap, MEMORY));
      fail();
    } catch (IllegalStateException ignored) {
    }
  }
}

            

Reported by PMD.

Found 'DU'-anomaly for variable 'bad' (lines '96'-'117').
Error

Line: 96

                }

  @Test public void recyclingInSuccessThrowsException() {
    BitmapTarget bad = new BitmapTarget() {
      @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        bitmap.recycle();
      }

      @Override public void onBitmapFailed(Exception e, Drawable errorDrawable) {

            

Reported by PMD.

picasso/src/main/java/com/squareup/picasso3/BitmapUtils.java
12 issues
This class has too many methods, consider refactoring it.
Design

Line: 42

              import static android.os.Build.VERSION.SDK_INT;
import static com.squareup.picasso3.Utils.checkNotNull;

final class BitmapUtils {
  /**
   * Lazily create {@link BitmapFactory.Options} based in given
   * {@link Request}, only instantiating them if needed.
   */
  @Nullable static BitmapFactory.Options createBitmapOptions(Request data) {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 145

                    bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
    } else {
      if (calculateSize) {
        BitmapFactory.decodeStream(bufferedSource.peek().inputStream(), null, options);
        calculateInSampleSize(request.targetWidth, request.targetHeight,
            checkNotNull(options, "options == null"), request);
      }
      bitmap = BitmapFactory.decodeStream(bufferedSource.inputStream(), null, options);
    }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 160

              
  static Bitmap decodeResource(Context context, Request request)
      throws IOException {
    if (SDK_INT >= 28) {
      return decodeResourceP(context, request);
    }

    Resources resources = Utils.getResources(context, request);
    int id = Utils.getResourceId(resources, request);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 195

                        @NonNull ImageDecoder.ImageInfo imageInfo, @NonNull ImageDecoder.Source source) {
        if (request.hasSize()) {
          Size size = imageInfo.getSize();
          if (shouldResize(request.onlyScaleDown, size.getWidth(), size.getHeight(),
              request.targetWidth, request.targetHeight)) {
            imageDecoder.setTargetSize(request.targetWidth, request.targetHeight);
          }
        }
      }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 195

                        @NonNull ImageDecoder.ImageInfo imageInfo, @NonNull ImageDecoder.Source source) {
        if (request.hasSize()) {
          Size size = imageInfo.getSize();
          if (shouldResize(request.onlyScaleDown, size.getWidth(), size.getHeight(),
              request.targetWidth, request.targetHeight)) {
            imageDecoder.setTargetSize(request.targetWidth, request.targetHeight);
          }
        }
      }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 208

                  TypedValue typedValue = new TypedValue();
    resources.getValue(drawableId, typedValue, true);
    CharSequence file = typedValue.string;
    return file != null && file.toString().endsWith(".xml");
  }

  static final class ExceptionCatchingSource extends ForwardingSource {
    @Nullable IOException thrownException;


            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 208

                  TypedValue typedValue = new TypedValue();
    resources.getValue(drawableId, typedValue, true);
    CharSequence file = typedValue.string;
    return file != null && file.toString().endsWith(".xml");
  }

  static final class ExceptionCatchingSource extends ForwardingSource {
    @Nullable IOException thrownException;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 212

                }

  static final class ExceptionCatchingSource extends ForwardingSource {
    @Nullable IOException thrownException;

    ExceptionCatchingSource(Source delegate) {
      super(delegate);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'options' (lines '49'-'51').
Error

Line: 49

                 */
  @Nullable static BitmapFactory.Options createBitmapOptions(Request data) {
    final boolean justBounds = data.hasSize();
    BitmapFactory.Options options = null;
    if (justBounds || data.config != null || data.purgeable) {
      options = new BitmapFactory.Options();
      options.inJustDecodeBounds = justBounds;
      options.inInputShareable = data.purgeable;
      options.inPurgeable = data.purgeable;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'sampleSize' (lines '80'-'85').
Error

Line: 80

              
  static void calculateInSampleSize(int reqWidth, int reqHeight, int width, int height,
      BitmapFactory.Options options, Request request) {
    int sampleSize = 1;
    if (height > reqHeight || width > reqWidth) {
      final int heightRatio;
      final int widthRatio;
      if (reqHeight == 0) {
        sampleSize = (int) Math.floor((float) width / (float) reqWidth);

            

Reported by PMD.

picasso/src/oldTests/java/com/squareup/picasso3/ImageViewActionTest.java
12 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 67

                  ImageViewAction request =
        new ImageViewAction(picasso, target, null, null, 0, false, callback);
    request.complete(new RequestHandler.Result(bitmap, MEMORY));
    verify(target).setImageDrawable(any(PicassoDrawable.class));
    verify(callback).onSuccess();
  }

  @Test
  public void invokesTargetAndCallbackErrorIfTargetIsNotNullWithErrorResourceId() {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 68

                      new ImageViewAction(picasso, target, null, null, 0, false, callback);
    request.complete(new RequestHandler.Result(bitmap, MEMORY));
    verify(target).setImageDrawable(any(PicassoDrawable.class));
    verify(callback).onSuccess();
  }

  @Test
  public void invokesTargetAndCallbackErrorIfTargetIsNotNullWithErrorResourceId() {
    ImageView target = mockImageViewTarget();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 82

              
    request.error(e);

    verify(target).setImageResource(RESOURCE_ID_1);
    verify(callback).onError(e);
  }

  @Test
  public void invokesErrorIfTargetIsNotNullWithErrorResourceId() {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 83

                  request.error(e);

    verify(target).setImageResource(RESOURCE_ID_1);
    verify(callback).onError(e);
  }

  @Test
  public void invokesErrorIfTargetIsNotNullWithErrorResourceId() {
    ImageView target = mockImageViewTarget();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 97

              
    request.error(e);

    verify(target).setImageResource(RESOURCE_ID_1);
    verify(callback).onError(e);
  }

  @Test
  public void invokesErrorIfTargetIsNotNullWithErrorDrawable() {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 98

                  request.error(e);

    verify(target).setImageResource(RESOURCE_ID_1);
    verify(callback).onError(e);
  }

  @Test
  public void invokesErrorIfTargetIsNotNullWithErrorDrawable() {
    Drawable errorDrawable = mock(Drawable.class);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 113

              
    request.error(e);

    verify(target).setImageDrawable(errorDrawable);
    verify(callback).onError(e);
  }

  @Test
  public void clearsCallbackOnCancel() {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 114

                  request.error(e);

    verify(target).setImageDrawable(errorDrawable);
    verify(callback).onError(e);
  }

  @Test
  public void clearsCallbackOnCancel() {
    Picasso picasso = mock(Picasso.class);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 125

                  ImageViewAction request =
        new ImageViewAction(picasso, target, null, null, 0, false, callback);
    request.cancel();
    assertThat(request.callback).isNull();
  }

  @Test
  public void stopPlaceholderAnimationOnError() {
    Picasso picasso = mock(Picasso.class);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 133

                  Picasso picasso = mock(Picasso.class);
    AnimationDrawable placeholder = mock(AnimationDrawable.class);
    ImageView target = mockImageViewTarget();
    when(target.getDrawable()).thenReturn(placeholder);
    ImageViewAction request =
        new ImageViewAction(picasso, target, null, null, 0, false, null);
    request.error(new RuntimeException());
    verify(placeholder).stop();
  }

            

Reported by PMD.

picasso/src/oldTests/java/com/squareup/picasso3/RemoteViewsActionTest.java
11 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 48

              @RunWith(RobolectricTestRunner.class) //
public class RemoteViewsActionTest {

  private Picasso picasso;
  private RemoteViews remoteViews;

  @Before public void setUp() {
    picasso = createPicasso();
    remoteViews = mock(RemoteViews.class);

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 49

              public class RemoteViewsActionTest {

  private Picasso picasso;
  private RemoteViews remoteViews;

  @Before public void setUp() {
    picasso = createPicasso();
    remoteViews = mock(RemoteViews.class);
    when(remoteViews.getLayoutId()).thenReturn(android.R.layout.list_content);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 54

                @Before public void setUp() {
    picasso = createPicasso();
    remoteViews = mock(RemoteViews.class);
    when(remoteViews.getLayoutId()).thenReturn(android.R.layout.list_content);
  }

  @Test public void completeSetsBitmapOnRemoteViews() {
    Callback callback = mockCallback();
    Bitmap bitmap = makeBitmap();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 62

                  Bitmap bitmap = makeBitmap();
    RemoteViewsAction action = createAction(callback);
    action.complete(new RequestHandler.Result(bitmap, NETWORK));
    verify(remoteViews).setImageViewBitmap(1, bitmap);
    verify(callback).onSuccess();
  }

  @Test public void errorWithNoResourceIsNoop() {
    Callback callback = mockCallback();

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 63

                  RemoteViewsAction action = createAction(callback);
    action.complete(new RequestHandler.Result(bitmap, NETWORK));
    verify(remoteViews).setImageViewBitmap(1, bitmap);
    verify(callback).onSuccess();
  }

  @Test public void errorWithNoResourceIsNoop() {
    Callback callback = mockCallback();
    RemoteViewsAction action = createAction(callback);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 70

                  Callback callback = mockCallback();
    RemoteViewsAction action = createAction(callback);
    Exception e = new RuntimeException();
    action.error(e);
    verifyZeroInteractions(remoteViews);
    verify(callback).onError(e);
  }

  @Test public void errorWithResourceSetsResource() {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 72

                  Exception e = new RuntimeException();
    action.error(e);
    verifyZeroInteractions(remoteViews);
    verify(callback).onError(e);
  }

  @Test public void errorWithResourceSetsResource() {
    Callback callback = mockCallback();
    RemoteViewsAction action = createAction(1, callback);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 79

                  Callback callback = mockCallback();
    RemoteViewsAction action = createAction(1, callback);
    Exception e = new RuntimeException();
    action.error(e);
    verify(remoteViews).setImageViewResource(1, 1);
    verify(callback).onError(e);
  }

  @Test public void clearsCallbackOnCancel() {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 80

                  RemoteViewsAction action = createAction(1, callback);
    Exception e = new RuntimeException();
    action.error(e);
    verify(remoteViews).setImageViewResource(1, 1);
    verify(callback).onError(e);
  }

  @Test public void clearsCallbackOnCancel() {
    Picasso picasso = mock(Picasso.class);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 81

                  Exception e = new RuntimeException();
    action.error(e);
    verify(remoteViews).setImageViewResource(1, 1);
    verify(callback).onError(e);
  }

  @Test public void clearsCallbackOnCancel() {
    Picasso picasso = mock(Picasso.class);
    ImageView target = mockImageViewTarget();

            

Reported by PMD.

picasso/src/main/java/com/squareup/picasso3/NetworkRequestHandler.java
11 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 38

                private static final String SCHEME_HTTP = "http";
  private static final String SCHEME_HTTPS = "https";

  private final Call.Factory callFactory;

  NetworkRequestHandler(Call.Factory callFactory) {
    this.callFactory = callFactory;
  }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 48

                  Uri uri = data.uri;
    if (uri == null) return false;

    String scheme = uri.getScheme();
    return (SCHEME_HTTP.equalsIgnoreCase(scheme) || SCHEME_HTTPS.equalsIgnoreCase(scheme));
  }

  @Override public void load(@NonNull final Picasso picasso, @NonNull final Request request,
      @NonNull final Callback callback) {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 69

                      // Sometimes response content length is zero when requests are being replayed. Haven't found
        // root cause to this but retrying the request seems safe to do so.
        ResponseBody body = response.body();
        if (loadedFrom == DISK && body.contentLength() == 0) {
          body.close();
          callback.onError(
              new ContentLengthException("Received response with 0 content-length header."));
          return;
        }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 75

                            new ContentLengthException("Received response with 0 content-length header."));
          return;
        }
        if (loadedFrom == NETWORK && body.contentLength() > 0) {
          picasso.downloadFinished(body.contentLength());
        }
        try {
          Bitmap bitmap = decodeStream(body.source(), request);
          callback.onSuccess(new Result.Bitmap(bitmap, loadedFrom));

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 124

                  }

    Uri uri = checkNotNull(request.uri, "request.uri == null");
    okhttp3.Request.Builder builder = new okhttp3.Request.Builder().url(uri.toString());
    if (cacheControl != null) {
      builder.cacheControl(cacheControl);
    }
    return builder.build();
  }

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 131

                  return builder.build();
  }

  static class ContentLengthException extends RuntimeException {
    ContentLengthException(String message) {
      super(message);
    }
  }


            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 137

                  }
  }

  static final class ResponseException extends RuntimeException {
    final int code;
    final int networkPolicy;

    ResponseException(int code, int networkPolicy) {
      super("HTTP " + code);

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 138

                }

  static final class ResponseException extends RuntimeException {
    final int code;
    final int networkPolicy;

    ResponseException(int code, int networkPolicy) {
      super("HTTP " + code);
      this.code = code;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 139

              
  static final class ResponseException extends RuntimeException {
    final int code;
    final int networkPolicy;

    ResponseException(int code, int networkPolicy) {
      super("HTTP " + code);
      this.code = code;
      this.networkPolicy = networkPolicy;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'cacheControl' (lines '106'-'110').
Error

Line: 106

                }

  private static okhttp3.Request createRequest(Request request) {
    CacheControl cacheControl = null;
    int networkPolicy = request.networkPolicy;
    if (networkPolicy != 0) {
      if (NetworkPolicy.isOfflineOnly(networkPolicy)) {
        cacheControl = CacheControl.FORCE_CACHE;
      } else {

            

Reported by PMD.

picasso/src/main/java/com/squareup/picasso3/PicassoDrawable.java
9 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 78

                  }
  }

  private final boolean debugging;
  private final float density;
  private final Picasso.LoadedFrom loadedFrom;

  @Nullable Drawable placeholder;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 79

                }

  private final boolean debugging;
  private final float density;
  private final Picasso.LoadedFrom loadedFrom;

  @Nullable Drawable placeholder;

  long startTimeMillis;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 80

              
  private final boolean debugging;
  private final float density;
  private final Picasso.LoadedFrom loadedFrom;

  @Nullable Drawable placeholder;

  long startTimeMillis;
  boolean animating;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 82

                private final float density;
  private final Picasso.LoadedFrom loadedFrom;

  @Nullable Drawable placeholder;

  long startTimeMillis;
  boolean animating;
  int alpha = 0xFF;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 84

              
  @Nullable Drawable placeholder;

  long startTimeMillis;
  boolean animating;
  int alpha = 0xFF;

  PicassoDrawable(Context context, Bitmap bitmap, @Nullable Drawable placeholder,
      Picasso.LoadedFrom loadedFrom, boolean noFade, boolean debugging) {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 85

                @Nullable Drawable placeholder;

  long startTimeMillis;
  boolean animating;
  int alpha = 0xFF;

  PicassoDrawable(Context context, Bitmap bitmap, @Nullable Drawable placeholder,
      Picasso.LoadedFrom loadedFrom, boolean noFade, boolean debugging) {
    super(context.getResources(), bitmap);

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 86

              
  long startTimeMillis;
  boolean animating;
  int alpha = 0xFF;

  PicassoDrawable(Context context, Bitmap bitmap, @Nullable Drawable placeholder,
      Picasso.LoadedFrom loadedFrom, boolean noFade, boolean debugging) {
    super(context.getResources(), bitmap);


            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 110

                    super.draw(canvas);
    } else {
      float normalized = (SystemClock.uptimeMillis() - startTimeMillis) / FADE_DURATION;
      if (normalized >= 1f) {
        animating = false;
        placeholder = null;
        super.draw(canvas);
      } else {
        if (placeholder != null) {

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 112

                    float normalized = (SystemClock.uptimeMillis() - startTimeMillis) / FADE_DURATION;
      if (normalized >= 1f) {
        animating = false;
        placeholder = null;
        super.draw(canvas);
      } else {
        if (placeholder != null) {
          placeholder.draw(canvas);
        }

            

Reported by PMD.

picasso-pollexor/src/main/java/com/squareup/picasso3/pollexor/PollexorRequestTransformer.java
9 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 20

               * By default images are only transformed with Thumbor if they have a size set.
 */
public class PollexorRequestTransformer implements RequestTransformer {
  private final Thumbor thumbor;
  private final boolean alwaysTransform;

  /** Create a transformer for the specified {@link Thumbor}. */
  public PollexorRequestTransformer(@NonNull Thumbor thumbor) {
    this(thumbor, false);

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 21

               */
public class PollexorRequestTransformer implements RequestTransformer {
  private final Thumbor thumbor;
  private final boolean alwaysTransform;

  /** Create a transformer for the specified {@link Thumbor}. */
  public PollexorRequestTransformer(@NonNull Thumbor thumbor) {
    this(thumbor, false);
  }

            

Reported by PMD.

The method 'transformRequest(Request)' has an NPath complexity of 288, current threshold is 200
Design

Line: 37

                  this.alwaysTransform = alwaysTransform;
  }

  @NonNull @Override public Request transformRequest(@NonNull Request request) {
    if (request.resourceId != 0) {
      return request; // Don't transform resource requests.
    }
    Uri uri = request.uri;
    if (uri == null) {

            

Reported by PMD.

The method 'transformRequest(Request)' has a cyclomatic complexity of 11.
Design

Line: 37

                  this.alwaysTransform = alwaysTransform;
  }

  @NonNull @Override public Request transformRequest(@NonNull Request request) {
    if (request.resourceId != 0) {
      return request; // Don't transform resource requests.
    }
    Uri uri = request.uri;
    if (uri == null) {

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 43

                  }
    Uri uri = request.uri;
    if (uri == null) {
      throw new IllegalArgumentException("Null uri passed to " + getClass().getCanonicalName());
    }
    String scheme = uri.getScheme();
    if (!"https".equals(scheme) && !"http".equals(scheme)) {
      return request; // Thumbor only supports remote images.
    }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 45

                  if (uri == null) {
      throw new IllegalArgumentException("Null uri passed to " + getClass().getCanonicalName());
    }
    String scheme = uri.getScheme();
    if (!"https".equals(scheme) && !"http".equals(scheme)) {
      return request; // Thumbor only supports remote images.
    }
    // Only transform requests that have resizes unless `alwaysTransform` is set.
    if (!request.hasSize() && !alwaysTransform) {

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 58

                  Request.Builder newRequest = request.newBuilder();

    // Create the url builder to use.
    ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString());

    // Resize the image to the target size if it has a size.
    if (request.hasSize()) {
      urlBuilder.resize(request.targetWidth, request.targetHeight);
      newRequest.clearResize();

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 78

                  }

    // Update the request with the completed Thumbor URL.
    newRequest.setUri(Uri.parse(urlBuilder.toUrl()));

    return newRequest.build();
  }
}

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 80

                  // Update the request with the completed Thumbor URL.
    newRequest.setUri(Uri.parse(urlBuilder.toUrl()));

    return newRequest.build();
  }
}

            

Reported by PMD.

picasso/src/oldTests/java/com/squareup/picasso3/MemoryPolicyTest.java
4 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 12

                @Test public void dontReadFromMemoryCache() {
    int memoryPolicy = 0;
    memoryPolicy |= MemoryPolicy.NO_CACHE.index;
    assertThat(MemoryPolicy.shouldReadFromMemoryCache(memoryPolicy)).isFalse();
  }

  @Test public void readFromMemoryCache() {
    int memoryPolicy = 0;
    memoryPolicy |= MemoryPolicy.NO_STORE.index;

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 18

                @Test public void readFromMemoryCache() {
    int memoryPolicy = 0;
    memoryPolicy |= MemoryPolicy.NO_STORE.index;
    assertThat(MemoryPolicy.shouldReadFromMemoryCache(memoryPolicy)).isTrue();
  }

  @Test public void dontWriteToMemoryCache() {
    int memoryPolicy = 0;
    memoryPolicy |= MemoryPolicy.NO_STORE.index;

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 24

                @Test public void dontWriteToMemoryCache() {
    int memoryPolicy = 0;
    memoryPolicy |= MemoryPolicy.NO_STORE.index;
    assertThat(MemoryPolicy.shouldWriteToMemoryCache(memoryPolicy)).isFalse();
  }

  @Test public void writeToMemoryCache() {
    int memoryPolicy = 0;
    memoryPolicy |= MemoryPolicy.NO_CACHE.index;

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 30

                @Test public void writeToMemoryCache() {
    int memoryPolicy = 0;
    memoryPolicy |= MemoryPolicy.NO_CACHE.index;
    assertThat(MemoryPolicy.shouldWriteToMemoryCache(memoryPolicy)).isTrue();
  }
}

            

Reported by PMD.

picasso/src/oldTests/java/com/squareup/picasso3/TestTransformation.java
4 issues
Field key has the same name as a method
Error

Line: 21

              import android.graphics.Bitmap;

class TestTransformation implements Transformation {
  private final String key;
  private final Bitmap result;

  TestTransformation(String key) {
    this(key, Bitmap.createBitmap(10, 10, null));
  }

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 21

              import android.graphics.Bitmap;

class TestTransformation implements Transformation {
  private final String key;
  private final Bitmap result;

  TestTransformation(String key) {
    this(key, Bitmap.createBitmap(10, 10, null));
  }

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 22

              
class TestTransformation implements Transformation {
  private final String key;
  private final Bitmap result;

  TestTransformation(String key) {
    this(key, Bitmap.createBitmap(10, 10, null));
  }


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 39

                    return source;
    }

    bitmap.recycle();
    return new RequestHandler.Result(result, source.getLoadedFrom(), source.getExifRotation());
  }

  @Override public String key() {
    return key;

            

Reported by PMD.

picasso/src/main/java/com/squareup/picasso3/PicassoExecutorService.java
3 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 48

              
  private static final class PicassoFutureTask extends FutureTask<BitmapHunter>
      implements Comparable<PicassoFutureTask> {
    private final BitmapHunter hunter;

    PicassoFutureTask(BitmapHunter hunter) {
      super(hunter, null);
      this.hunter = hunter;
    }

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 62

              
      // High-priority requests are "lesser" so they are sorted to the front.
      // Equal priorities are sorted by sequence number to provide FIFO ordering.
      return (p1 == p2 ? hunter.sequence - other.hunter.sequence : p2.ordinal() - p1.ordinal());
    }
  }
}

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 62

              
      // High-priority requests are "lesser" so they are sorted to the front.
      // Equal priorities are sorted by sequence number to provide FIFO ordering.
      return (p1 == p2 ? hunter.sequence - other.hunter.sequence : p2.ordinal() - p1.ordinal());
    }
  }
}

            

Reported by PMD.