Duplicated block of Code in Sonar for import statements in Java

tuk picture tuk · Mar 20, 2016 · Viewed 47.5k times · Source

In Sonar 4.5.6 (with default settings) I am seeing Duplicated Blocks message as

enter image description here

My java code for which I am getting the message is like below:-

package com.jabong.orchestratorservice.adapter.order.endpoints;

import com.jabong.orchestratorservice.adapter.order.request.UpdateOrderStatusReadyShipRequest;

public class UpdateOrderReadyShipEndPoint extends BaseOrderEndPoint {
    private final static String API_NAME = "setStatusToReadyToShip";

    @Override
    public String getSourceEndPoint() {
    return new StringBuilder("direct:").append(API_NAME).toString();
    }

    @Override
    public String getDestinationEndPoint() {
    return new StringBuilder("bean:orderHelper?method=").append(API_NAME).toString();
    }

    @Override
    protected String getName() {
    return API_NAME;
    }

    @Override
    protected String getApiInputClassName() {
    return UpdateOrderStatusReadyShipRequest.class.getName();
    }
}

UpdateOrderStatusReadyShipRequest also does not import UpdateOrderReadyShipEndPoint

package com.jabong.orchestratorservice.adapter.order.request;

public class UpdateOrderStatusReadyShipRequest extends BaseOrderRequest {

Can some let me know what does this mean?

Answer

G. Ann - SonarSource Team picture G. Ann - SonarSource Team · Mar 21, 2016

The Duplicate Blocks rule raises issues at the file level. So it's not trying to tell you that your import statement is duplicated, but that somewhere in the file is a duplicate block. If you'll scroll down, you should see a vertical yellow/orange bar in the left margin. It marks the duplicate block. Click on the bar to get details of where the block is duplicated.

EDIT In more recent versions the duplication marker is brown or gray.