簡體   English   中英

sonarQube - 使字段瞬態或可序列化

[英]sonarQube - make field transient or serializable

我正在嘗試解決由Jenkins的sonarQube插件報告的以下違規行為:“make'update'transient或serializable。”。 重力:關鍵,標記:序列化。

我有以下共享接口

public interface MPUpdate {

    void apply( SoapService svc, byte[] jerseyClientResp ) throws MPException ;
}

以下枚舉是應用程序邏輯的入口點

public enum DomainResource implements MPUpdate {

    PROGRAMMES( new ProgrammeUpdate() ),
    PRODUCTIONS( new ProductionUpdate() );
    // more enums

    private DomainResource( MPUpdate update ) {
        this.update = update;
    }

    private final MPUpdate update; // Sonar: make "update" transient or serializable, priority: critical, tag: serialization

    @Override
    public void apply( SoapService svc, byte[] jerseyClientResp ) throws MPException {
        update.apply( svc, jerseyClientResp );      
    }
}

通過枚舉初始化的邏輯單元之一

public class ProgrammeUpdate implements MPUpdate {

    private final ResponseConverter<ProgrammeDto> responseConverter = new ResponseConverter<>( ProgrammeDto.class );

    @Override
    public void apply( SoapService svc, byte[] jerseyClientResp ) throws MPException {

        // APPLICATION LOGIC
    }

}

最后這是它的使用方式:

...
String levelFromUrl = getLevel(); // eg. "programmes"
MPUpdate resource;
resource = DomainResource.valueOf( levelFromUrl.toUpperCase() ); 
...
resource.apply( soapService, jerseyClientOutcome );
...

有幫助嗎? 枚舉的使用是否提高了日志記錄的性能?

非常感謝

您不需要它可序列化。 你應該把它標記為瞬態。 使用簡單名稱字符串序列化枚舉,因此其他字段無關緊要。 只是將該字段標記為瞬態以使聲納快樂(盡管該工具本身應該能夠確定這種情況)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM