首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取重数为0到1的导航属性的VDM调用,为0响应提供NullPointerException

获取重数为0到1的导航属性的VDM调用,为0响应提供NullPointerException
EN

Stack Overflow用户
提问于 2019-10-04 18:38:03
回答 1查看 136关注 0票数 0

我使用VDM来获取重数为0..1的导航属性。

每当从S4返回的响应是0(即“204No Content")时,我就会得到一个NullPointerException

代码语言:javascript
复制
HeaderCDSForPRForGuidedBuying requisitionHeader = isActiveEntity ? readActivatedHeader(purchaseRequisition) : readHeaderInternal(draftUUID);
    GuidedProcurementDeliveryAddressAtHeader requisitionHeaderAddress;

    requisitionHeaderAddress = requisitionHeader.getGuidedProcmtReqnDelivAddrOrFetch();

    return S4ToGBServiceMapper.mapToRequisitionHeader(requisitionHeader, requisitionHeaderAddress);

这里的requisitionHeader.getGuidedProcmtReqnDelivAddrOrFetch();是导航实体,只要没有数据,它就会从S4中产生“204No Content”。

实体的元数据

代码语言:javascript
复制
    <EntityType Name="C_GuidedProcmtReqnHdrTPType" sap:label="Header CDS 
     for PR for guided buying" sap:content-version="1">
<Key> 
<PropertyRef Name="PurchaseRequisition"/>
<PropertyRef Name="DraftUUID"/>
<PropertyRef Name="IsActiveEntity"/>
</Key>
<Property Name="Activation_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Edit_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Preparation_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Validation_ac" Type="Edm.Boolean" sap:label="Dyn. Action Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurReqnDescription_fc" Type="Edm.Byte" sap:label="Dyn. Field Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurReqnSSPRequestor_fc" Type="Edm.Byte" sap:label="Dyn. Field Control" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurchaseRequisition" Type="Edm.String" Nullable="false" MaxLength="10" sap:display-format="UpperCase" sap:label="Purchase requisition" sap:quickinfo="Purchase requisition number" sap:value-list="standard"/>
<Property Name="PurReqnDescription" Type="Edm.String" MaxLength="40" sap:field-control="PurReqnDescription_fc" sap:label="Purchase Requisition Name" sap:quickinfo="Short Text"/>
<Property Name="PurReqnSSPRequestor" Type="Edm.String" MaxLength="60" sap:field-control="PurReqnSSPRequestor_fc" sap:label="Requestor" sap:value-list="standard"/>
<Property Name="PurReqnSSPAuthor" Type="Edm.String" MaxLength="12" sap:display-format="UpperCase" sap:label="Author" sap:quickinfo="Author of Requisition"/>
<Property Name="PurchaseRequisitionType" Type="Edm.String" MaxLength="4" sap:display-format="UpperCase" sap:label="Document Type" sap:quickinfo="Purchase Requisition Document Type"/>
<Property Name="CreationDate" Type="Edm.DateTime" Precision="0" sap:display-format="Date" sap:label="Created On"/>
<Property Name="EmployeeFullName" Type="Edm.String" MaxLength="80" sap:label="Requested By" sap:quickinfo="Full Name of Person"/>
<Property Name="PurReqnOrigin" Type="Edm.String" MaxLength="1" sap:display-format="UpperCase" sap:label="Creation indicator" sap:quickinfo="Creation indicator (purchase requisition/schedule lines)"/>
<Property Name="PurReqnLifeCycleStatus" Type="Edm.String" MaxLength="2" sap:display-format="UpperCase" sap:label="LifeCycle Status" sap:quickinfo="Purchase requistion status" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PurReqnLifeCycleStatusName" Type="Edm.String" MaxLength="60" sap:label="Status" sap:quickinfo="Short Text for Fixed Values" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="NumberOfItems" Type="Edm.Int32" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="TotalNetAmount" Type="Edm.Decimal" Precision="16" Scale="3" sap:unit="Currency" sap:label="Total Net Value" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Currency" Type="Edm.String" MaxLength="5" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:semantics="currency-code"/>
<Property Name="IsSrchEnabled" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Hide Search Bar" sap:creatable="false" sap:updatable="false"/>
<Property Name="IsExtPurgScenario" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Is External Purch." sap:quickinfo="Indicator for external purchasing scenario" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="IsOnBehalfCart" Type="Edm.String" MaxLength="1" sap:display-format="UpperCase" sap:label="Shop On Behalf Ind." sap:quickinfo="Shop on behalf indicator"/>
<Property Name="PurReqnIsCopyDraft" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Draft Is Copied" sap:quickinfo="Draft is copied from active document"/>
<Property Name="BusinessUser" Type="Edm.String" MaxLength="12" sap:display-format="UpperCase" sap:label="User ID"/>
<Property Name="PurReqnIsCreatedInExpertMode" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="PR in Expert Mode" sap:quickinfo="PR Created in Expert Mode"/>
<Property Name="AccountAssignmentCategory" Type="Edm.String" MaxLength="1" sap:display-format="UpperCase" sap:label="Acct Assignment Cat." sap:quickinfo="Account Assignment Category" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="AcctAssignmentCategoryName" Type="Edm.String" MaxLength="20" sap:label="AcctAssgntCateg Desc" sap:quickinfo="Account Assignment Category Description" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PrimaryCostObject" Type="Edm.String" MaxLength="30" sap:display-format="UpperCase" sap:label="Primary Cost Object" sap:quickinfo="Account Assignment Primary Cost Object" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="PrimaryCostObjectName" Type="Edm.String" MaxLength="60" sap:display-format="UpperCase" sap:label="Prim. Cost Obj. Name" sap:quickinfo="Account Assignment Primary Cost Object Name" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="DeliveryDurationInDays" Type="Edm.Decimal" Precision="3" Scale="0" sap:label="Delivery time (days)" sap:quickinfo="Delivery time in days" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="DeliveryTime" Type="Edm.Decimal" Precision="3" Scale="0" sap:label="Delivery time (days)" sap:quickinfo="Delivery time in days" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="DeliveryDate" Type="Edm.DateTime" Precision="0" sap:display-format="Date" sap:label="Delivery date" sap:quickinfo="Item delivery date" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="HasDraftEntity" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Has Draft" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="DraftUUID" Type="Edm.Guid" Nullable="false" sap:label="Key" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="DraftEntityCreationDateTime" Type="Edm.DateTimeOffset" Precision="7" sap:label="Draft Created On" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="DraftEntityLastChangeDateTime" Type="Edm.DateTimeOffset" Precision="7" sap:label="Draft Last Changed On" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="HasActiveEntity" Type="Edm.Boolean" sap:display-format="UpperCase" sap:label="Has active" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<Property Name="IsActiveEntity" Type="Edm.Boolean" Nullable="false" sap:display-format="UpperCase" sap:label="Is active" sap:heading="" sap:quickinfo="" sap:creatable="false" sap:updatable="false"/>
<NavigationProperty Name="DraftAdministrativeData" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_76A4502D0F516EE52DD3CBBBE346E4D9" FromRole="FromRole_assoc_76A4502D0F516EE52DD3CBBBE346E4D9" ToRole="ToRole_assoc_76A4502D0F516EE52DD3CBBBE346E4D9"/>
<NavigationProperty Name="SiblingEntity" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_3CC1A0E5A29B95AA58385E4B4E670133" FromRole="FromRole_assoc_3CC1A0E5A29B95AA58385E4B4E670133" ToRole="ToRole_assoc_3CC1A0E5A29B95AA58385E4B4E670133"/>
<NavigationProperty Name="to_GuidedProcmtReqnDelivAddr" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_ABFFAA8E73382AA60F058244C4ABBB35" FromRole="FromRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35" ToRole="ToRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>
<NavigationProperty Name="to_GuidedProcmtReqnUserDefaults" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_1579C23A5F4ED87BDC6BD58F2005A338" FromRole="FromRole_assoc_1579C23A5F4ED87BDC6BD58F2005A338" ToRole="ToRole_assoc_1579C23A5F4ED87BDC6BD58F2005A338"/>
<NavigationProperty Name="to_Purchaserequisitionitem_Wd" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_3F09BE43BBC7F408BF50540B885968FB" FromRole="FromRole_assoc_3F09BE43BBC7F408BF50540B885968FB" ToRole="ToRole_assoc_3F09BE43BBC7F408BF50540B885968FB"/>
<NavigationProperty Name="to_PurReqnEmplByCoOfAuthorVH" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_F51CC3D827FD02E8485693F0D8E2BECB" FromRole="FromRole_assoc_F51CC3D827FD02E8485693F0D8E2BECB" ToRole="ToRole_assoc_F51CC3D827FD02E8485693F0D8E2BECB"/>
<NavigationProperty Name="to_SSPReqnConfiguration" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_8453857C8C3E316B4D665A8FF57BD512" FromRole="FromRole_assoc_8453857C8C3E316B4D665A8FF57BD512" ToRole="ToRole_assoc_8453857C8C3E316B4D665A8FF57BD512"/>
</EntityType>

这里的问题是导航问题

代码语言:javascript
复制
<NavigationProperty Name="to_GuidedProcmtReqnDelivAddr" Relationship="MMPUR_REQ_GPR_MAINTAIN_SRV.assoc_ABFFAA8E73382AA60F058244C4ABBB35" FromRole="FromRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35" ToRole="ToRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>

<Association Name="assoc_ABFFAA8E73382AA60F058244C4ABBB35" sap:content-version="1">
<End Type="MMPUR_REQ_GPR_MAINTAIN_SRV.C_GuidedProcmtReqnHdrTPType" Multiplicity="1" Role="FromRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>
<End Type="MMPUR_REQ_GPR_MAINTAIN_SRV.C_GuidedProcmtReqnDelivAddrType" Multiplicity="0..1" Role="ToRole_assoc_ABFFAA8E73382AA60F058244C4ABBB35"/>
</Association>
EN

回答 1

Stack Overflow用户

发布于 2019-10-07 20:44:21

谢谢你的详细问题。

看起来您确实在一个与SAP Cloud SDK相关的间接使用的组件中发现了一个bug。我已经在票务系统中创建了一个事件(#1970496164)。目前还不清楚这个NullPointerException什么时候会被修复,希望在下一个即将到来的版本中。

同时,我建议使用VAVR库的Try API作为变通方法--在运行时处理错误。

代码语言:javascript
复制
import io.vavr.control.Try;

// ...

@Nonnull
HeaderCDSForPRForGuidedBuying requisitionHeader;

@Nullable
GuidedProcurementDeliveryAddressAtHeader requisitionHeaderAddress;

// tolerant error handling
requisitionHeaderAddress = Try.of(requisitionHeader::getGuidedProcmtReqnDelivAddrOrFetch).getOrNull();

return S4ToGBServiceMapper.mapToRequisitionHeader(requisitionHeader, requisitionHeaderAddress);

(假设您的mapToRequisitionHeader方法期望第二个参数为@Nullable)

将依赖添加到您的pom中:

代码语言:javascript
复制
<dependency>
  <groupId>io.vavr</groupId>
  <artifactId>vavr</artifactId>
  <version>0.10.2</version>
</dependency>

当然,作为我的建议的替代方案,您可以只使用笨重的try-catch块。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58234748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档