Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 37b344c

Browse files
[FAB-4235] Fix compile and Javadoc warnings
Fix to compile warnings due to code issues. * Minor logic errors. * Generic declarations and casts. * Resources not closed (now use try-with-resources) Resolve issues in existing Javadoc. Fixes for actual bugs flagged by Checkstyle * Two (static) utility classes with public constructors. * Peer class had equals() implementation but no hashCode(). Change-Id: I5484a93b3b36cb27761b297aaa33f8321f0f4d02 Signed-off-by: Mark S. Lewis <Mark_Lewis@uk.ibm.com>
1 parent 15d2faf commit 37b344c

31 files changed

+253
-289
lines changed

.classpath

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
<attribute name="maven.pomderived" value="true"/>
1919
</attributes>
2020
</classpathentry>
21-
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/proto">
22-
<attributes>
23-
<attribute name="maven.pomderived" value="true"/>
24-
</attributes>
25-
</classpathentry>
2621
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
2722
<attributes>
2823
<attribute name="optional" value="true"/>
@@ -39,5 +34,10 @@
3934
<attribute name="maven.pomderived" value="true"/>
4035
</attributes>
4136
</classpathentry>
37+
<classpathentry excluding="**" kind="src" output="target/classes" path="src">
38+
<attributes>
39+
<attribute name="maven.pomderived" value="true"/>
40+
</attributes>
41+
</classpathentry>
4242
<classpathentry kind="output" path="target/classes"/>
4343
</classpath>

src/main/java/org/hyperledger/fabric/sdk/ChaincodeEndorsementPolicy.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class ChaincodeEndorsementPolicy {
5151
public ChaincodeEndorsementPolicy() {
5252
}
5353

54-
private static SignaturePolicy parsePolicy(IndexedHashMap<String, MSPPrincipal> identities, Map mp) throws ChaincodeEndorsementPolicyParseException {
54+
private static SignaturePolicy parsePolicy(IndexedHashMap<String, MSPPrincipal> identities, Map<?, ?> mp) throws ChaincodeEndorsementPolicyParseException {
5555

5656
if (mp == null) {
5757
throw new ChaincodeEndorsementPolicyParseException("No policy section was found in the document.");
@@ -61,7 +61,7 @@ private static SignaturePolicy parsePolicy(IndexedHashMap<String, MSPPrincipal>
6161

6262
}
6363

64-
for (Map.Entry<Object, Object> ks : ((Map<Object, Object>) mp).entrySet()) {
64+
for (Map.Entry<?, ?> ks : mp.entrySet()) {
6565
Object ko = ks.getKey();
6666
Object vo = ks.getValue();
6767
final String key = (String) ko;
@@ -92,20 +92,23 @@ private static SignaturePolicy parsePolicy(IndexedHashMap<String, MSPPrincipal>
9292
int matchNo = Integer.parseInt(matchStingNo);
9393

9494
if (!(vo instanceof List)) {
95-
96-
throw new ChaincodeEndorsementPolicyParseException(format("%s expected to have list but found %s.", key, "" + vo));
95+
throw new ChaincodeEndorsementPolicyParseException(format("%s expected to have list but found %s.", key, String.valueOf(vo)));
9796
}
98-
if (((List) vo).size() < matchNo) {
9997

100-
throw new ChaincodeEndorsementPolicyParseException(format("%s expected to have at least %d items to match but only found %d.", key, matchNo, ((List) vo).size()));
98+
@SuppressWarnings("unchecked")
99+
final List<Map<?, ?>> voList = (List<Map<?, ?>>)vo;
100+
101+
if (voList.size() < matchNo) {
102+
103+
throw new ChaincodeEndorsementPolicyParseException(format("%s expected to have at least %d items to match but only found %d.", key, matchNo, voList.size()));
101104
}
102105

103106
SignaturePolicy.NOutOf.Builder spBuilder = SignaturePolicy.NOutOf.newBuilder()
104107
.setN(matchNo);
105108

106-
for (Object nlo : (List) vo) {
109+
for (Map<?, ?> nlo : voList) {
107110

108-
SignaturePolicy sp = parsePolicy(identities, (Map) nlo);
111+
SignaturePolicy sp = parsePolicy(identities, nlo);
109112
spBuilder.addPolicies(sp);
110113
}
111114

@@ -123,12 +126,12 @@ private static SignaturePolicy parsePolicy(IndexedHashMap<String, MSPPrincipal>
123126

124127
}
125128

126-
private static IndexedHashMap<String, MSPPrincipal> parseIdentities(Map<Object, Object> identities) throws ChaincodeEndorsementPolicyParseException {
129+
private static IndexedHashMap<String, MSPPrincipal> parseIdentities(Map<?, ?> identities) throws ChaincodeEndorsementPolicyParseException {
127130
//Only Role types are excepted at this time.
128131

129132
IndexedHashMap<String, MSPPrincipal> ret = new IndexedHashMap<>();
130133

131-
for (Map.Entry<Object, Object> kp : identities.entrySet()) {
134+
for (Map.Entry<?, ?> kp : identities.entrySet()) {
132135
Object key = kp.getKey();
133136
Object val = kp.getValue();
134137

@@ -144,13 +147,14 @@ private static IndexedHashMap<String, MSPPrincipal> parseIdentities(Map<Object,
144147
throw new ChaincodeEndorsementPolicyParseException(format("In identities with key %s value expected Map got %s ", key, val == null ? "null" : val.getClass().getName()));
145148
}
146149

147-
Object role = ((Map<String, Object>) val).get("role");
150+
Object role = ((Map<?, ?>) val).get("role");
148151

149152
if (!(role instanceof Map)) {
150153
throw new ChaincodeEndorsementPolicyParseException(format("In identities with key %s value expected Map for role got %s ", key, role == null ? "null" : role.getClass().getName()));
151154
}
155+
final Map<?, ?> roleMap = (Map<?, ?>)role;
152156

153-
Object name = ((Map) role).get("name");
157+
Object name = (roleMap).get("name");
154158

155159
if (!(name instanceof String)) {
156160
throw new ChaincodeEndorsementPolicyParseException(format("In identities with key %s name expected String in role got %s ", key, name == null ? "null" : name.getClass().getName()));
@@ -160,7 +164,7 @@ private static IndexedHashMap<String, MSPPrincipal> parseIdentities(Map<Object,
160164
throw new ChaincodeEndorsementPolicyParseException(format("In identities with key %s name expected member or admin in role got %s ", key, name));
161165
}
162166

163-
Object mspId = ((Map) role).get("mspId");
167+
Object mspId = roleMap.get("mspId");
164168

165169
if (!(mspId instanceof String)) {
166170
throw new ChaincodeEndorsementPolicyParseException(format("In identities with key %s mspId expected String in role got %s ", key, mspId == null ? "null" : mspId.getClass().getName()));
@@ -212,15 +216,15 @@ public void fromFile(File policyFile) throws IOException {
212216

213217
public void fromYamlFile(File yamlPolicyFile) throws IOException, ChaincodeEndorsementPolicyParseException {
214218
final Yaml yaml = new Yaml();
215-
final Map load = (Map) yaml.load(new FileInputStream(yamlPolicyFile));
219+
final Map<?, ?> load = (Map<?, ?>)yaml.load(new FileInputStream(yamlPolicyFile));
216220

217-
Map<String, Map> mp = (Map<String, Map>) load.get("policy");
221+
Map<?, ?> mp = (Map<?, ?>)load.get("policy");
218222

219223
if (null == mp) {
220224
throw new ChaincodeEndorsementPolicyParseException("The policy file has no policy section");
221225
}
222226

223-
IndexedHashMap<String, MSPPrincipal> identities = parseIdentities((Map<Object, Object>) load.get("identities"));
227+
IndexedHashMap<String, MSPPrincipal> identities = parseIdentities((Map<?, ?>)load.get("identities"));
224228

225229
SignaturePolicy sp = parsePolicy(identities, mp);
226230

@@ -258,6 +262,7 @@ public byte[] getChaincodeEndorsementPolicyAsBytes() {
258262
return policyBytes;
259263
}
260264

265+
@SuppressWarnings("serial")
261266
private static class IndexedHashMap<K, V> extends LinkedHashMap<K, V> {
262267
final HashMap<K, Integer> kmap = new HashMap<>();
263268

src/main/java/org/hyperledger/fabric/sdk/ChaincodeID.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,10 @@
1717
/**
1818
* ChaincodeID identifies chaincode.
1919
*/
20-
public class ChaincodeID {
20+
public final class ChaincodeID {
2121

2222
private final org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID fabricChaincodeID;
2323

24-
private ChaincodeID() {
25-
26-
fabricChaincodeID = null;
27-
28-
}
29-
3024
public org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID getFabricChaincodeID() {
3125
return fabricChaincodeID;
3226
}
@@ -53,7 +47,7 @@ public String getVersion() {
5347
* Build a new ChaincodeID
5448
*/
5549

56-
public static class Builder {
50+
public static final class Builder {
5751
private final org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID.Builder protoBuilder = org.hyperledger.fabric.protos.peer.Chaincode.ChaincodeID.newBuilder();
5852

5953
private Builder() {

0 commit comments

Comments
 (0)