AWS 源代码错误?
Error in AWS source code?
在我们的代码中,我们从 sqs 队列中删除一条消息并获得 deletResponse
。
String deleteResponse = sqsClient.deleteMessage(simBridge2ESBUrl, message.getReceiptHandle()).toString();
此调用后消息被删除,但 deleteResponse
始终是 {}
。于是我们查看了源码,发现DeleteMessageResult::toString
函数只做了return{}
。
以下是 AWS 源代码。 toString()
和 hashCode()
函数看起来很奇怪。源代码有错误还是我做错了?谢谢。
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights
* Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.services.sqs.model;
import java.io.Serializable;
/**
*
*/
public class DeleteMessageResult implements Serializable, Cloneable {
/**
* Returns a string representation of this object; useful for testing and
* debugging.
*
* @return A string representation of this object.
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("}");
return sb.toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (obj instanceof DeleteMessageResult == false)
return false;
DeleteMessageResult other = (DeleteMessageResult) obj;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int hashCode = 1;
return hashCode;
}
@Override
public DeleteMessageResult clone() {
try {
return (DeleteMessageResult) super.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException(
"Got a CloneNotSupportedException from Object.clone() "
+ "even though we're Cloneable!", e);
}
}
}
从编程的角度来看 toString()
编写正确。想想这个函数是做什么的:
A string representation of this object.
由于DeleteMessageResult
class没有属性,所以return也没什么。 hashCode()
同样适用。 DeleteMessageResult
的两个对象总是相同的,因此它们每次都具有相同的哈希值。
话虽这么说,我确实认为 DeleteMessageResult
应该包含 ResposeMetadata
和独特的 RequestId
,如 API reference:
所示
<DeleteMessageResponse>
<ResponseMetadata>
<RequestId>
b5293cb5-d306-4a17-9048-b263635abe42
</RequestId>
</ResponseMetadata>
</DeleteMessageResponse>
所以,是的,这个 class 可以(可能,应该)修补以完全支持 SQS API。
在我们的代码中,我们从 sqs 队列中删除一条消息并获得 deletResponse
。
String deleteResponse = sqsClient.deleteMessage(simBridge2ESBUrl, message.getReceiptHandle()).toString();
此调用后消息被删除,但 deleteResponse
始终是 {}
。于是我们查看了源码,发现DeleteMessageResult::toString
函数只做了return{}
。
以下是 AWS 源代码。 toString()
和 hashCode()
函数看起来很奇怪。源代码有错误还是我做错了?谢谢。
/*
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights
* Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.services.sqs.model;
import java.io.Serializable;
/**
*
*/
public class DeleteMessageResult implements Serializable, Cloneable {
/**
* Returns a string representation of this object; useful for testing and
* debugging.
*
* @return A string representation of this object.
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{");
sb.append("}");
return sb.toString();
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (obj instanceof DeleteMessageResult == false)
return false;
DeleteMessageResult other = (DeleteMessageResult) obj;
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int hashCode = 1;
return hashCode;
}
@Override
public DeleteMessageResult clone() {
try {
return (DeleteMessageResult) super.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException(
"Got a CloneNotSupportedException from Object.clone() "
+ "even though we're Cloneable!", e);
}
}
}
从编程的角度来看 toString()
编写正确。想想这个函数是做什么的:
A string representation of this object.
由于DeleteMessageResult
class没有属性,所以return也没什么。 hashCode()
同样适用。 DeleteMessageResult
的两个对象总是相同的,因此它们每次都具有相同的哈希值。
话虽这么说,我确实认为 DeleteMessageResult
应该包含 ResposeMetadata
和独特的 RequestId
,如 API reference:
<DeleteMessageResponse>
<ResponseMetadata>
<RequestId>
b5293cb5-d306-4a17-9048-b263635abe42
</RequestId>
</ResponseMetadata>
</DeleteMessageResponse>
所以,是的,这个 class 可以(可能,应该)修补以完全支持 SQS API。