怎么可以解决诡计:未经检验/未经证实的声纳投射? [英] how can resolve dodgy:unchecked/unconfirmed cast in sonar?
问题描述
@Override
public boolean validate(BaseInfo infoObject){
boolean isValid = true;
AckTransferPaymentInfo ackTransferPaymentInfo =(AckTransferPaymentInfo)infoObject;
Dodgy - 未选中/未确认的演员
从com.vocalink中取消选中/未确认的演员.acsw.common.validation.info.BaseInfo to com.vocalink.acsw.common.validation.info.AckTransferPaymentInfo in com.vocalink.acsw.validation.rule.T170Rule.validate(BaseInfo)
AckTransferPaymentElement payment = ackTransferPaymentInfo.getTransferPayment();
/ pre>
if(CreditDebitIndicator.CRDT.equals(ackTransferPaymentInfo.getCreditDebitIndicator())
&& ackTransferPaymentInfo.getOriginalPaymentAccount()。getAccountName()!= null
解决方案您可以检查infoObject的类型是否正确,如果不是,请妥善处理:
if(!(infoObject instanceof AckTransferPaymentInfo)){
throw new AssertionError(Unexpected type:+ infoObject);
}
AckTransferPaymentInfo ackTransferPaymentInfo =(AckTransferPaymentInfo)infoObject;
你应该验证这样做你想要的当infoObject为null时。
iam getting the exception through sonar in this following code.How can I resolve this.Suggest me.
@Override public boolean validate(BaseInfo infoObject) { boolean isValid = true; AckTransferPaymentInfo ackTransferPaymentInfo = (AckTransferPaymentInfo) infoObject;
Dodgy - Unchecked/unconfirmed cast
Unchecked/unconfirmed cast from com.vocalink.acsw.common.validation.info.BaseInfo to com.vocalink.acsw.common.validation.info.AckTransferPaymentInfo in com.vocalink.acsw.validation.rule.T170Rule.validate(BaseInfo)AckTransferPaymentElement payment = ackTransferPaymentInfo.getTransferPayment(); if(CreditDebitIndicator.CRDT.equals(ackTransferPaymentInfo.getCreditDebitIndicator()) && ackTransferPaymentInfo.getOriginalPaymentAccount().getAccountName() != null
解决方案You can check that the type of infoObject is correct and handle it appropriately when it's not:
if (!(infoObject instanceof AckTransferPaymentInfo)) { throw new AssertionError("Unexpected type: " + infoObject); } AckTransferPaymentInfo ackTransferPaymentInfo = (AckTransferPaymentInfo) infoObject;
You should verify this does what you want when infoObject is null.
这篇关于怎么可以解决诡计:未经检验/未经证实的声纳投射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!