Skip to content

Commit a047076

Browse files
committed
fix issues
1 parent 1978604 commit a047076

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

src/main/java/com/upokecenter/cbor/CBORCanonical.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private static byte[] CtapCanonicalEncode(CBORObject a, int depth) {
180180
}
181181
}
182182
} else if (valueAType == CBORType.Map) {
183-
Map.Entry<byte[], byte[]> kv;
183+
Map.Entry<byte[], byte[]> kv1;
184184
ArrayList<Map.Entry<byte[], byte[]>> sortedKeys;
185185
sortedKeys = new ArrayList<Map.Entry<byte[], byte[]>>();
186186
for (CBORObject key : cbor.getKeys()) {
@@ -190,27 +190,28 @@ private static byte[] CtapCanonicalEncode(CBORObject a, int depth) {
190190
}
191191
// Check if key and value can be canonically encoded
192192
// (will throw an exception if they cannot)
193-
kv = new AbstractMap.SimpleImmutableEntry<byte[], byte[]>(
193+
kv1 = new AbstractMap.SimpleImmutableEntry<byte[], byte[]>(
194194
CtapCanonicalEncode(key, depth + 1),
195195
CtapCanonicalEncode(cbor.get(key), depth + 1));
196-
sortedKeys.add(kv);
196+
sortedKeys.add(kv1);
197197
}
198-
Collections.sort(sortedKeys,ByteComparer);
198+
java.util.Collections.sort(sortedKeys, ByteComparer);
199199
{
200200
java.io.ByteArrayOutputStream ms = null;
201201
try {
202202
ms = new java.io.ByteArrayOutputStream();
203203

204204
CBORObject.WriteValue(ms, 5, cbor.size());
205205
byte[] lastKey = null;
206-
for (Map.Entry<byte[], byte[]> kv2 : sortedKeys) {
207-
byte[] bytes = kv2.getKey();
206+
for (int i = 0; i < sortedKeys.size(); ++i) {
207+
kv1 = sortedKeys.get(i);
208+
byte[] bytes = kv1.getKey();
208209
if (lastKey != null && ByteArraysEqual(bytes, lastKey)) {
209210
throw new CBORException("duplicate canonical CBOR key");
210211
}
211212
lastKey = bytes;
212213
ms.write(bytes, 0, bytes.length);
213-
bytes = kv2.getValue();
214+
bytes = kv1.getValue();
214215
ms.write(bytes, 0, bytes.length);
215216
}
216217
return ms.toByteArray();

src/test/java/com/upokecenter/test/CBORTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,25 +3197,23 @@ public void TestCtap2CanonicalDecodeEncode() {
31973197
bytes = cbor.EncodeToBytes(options);
31983198
try {
31993199
cbor2 = CBORObject.DecodeFromBytes(bytes, options);
3200-
} catch (Exception ex) {
3201-
System.out.println(ex.getMessage());
3202-
System.out.println(ex.getStackTrace());
3203-
Assert.fail(ex.toString());
3204-
throw new IllegalStateException("", ex);
3200+
} catch (Exception ex2) {
3201+
Assert.fail(ex2.toString());
3202+
throw new IllegalStateException("", ex2);
32053203
}
32063204
byte[] bytes2 = cbor2.EncodeToBytes(options);
32073205
TestCommon.AssertByteArraysEqual(bytes, bytes2);
3208-
} catch (CBORException ex) {
3206+
} catch (CBORException ex4) {
32093207
// Canonical encoding failed, so DecodeFromBytes must fail
32103208
bytes = cbor.EncodeToBytes();
32113209
try {
32123210
CBORObject.DecodeFromBytes(bytes, options);
32133211
Assert.fail("Should have failed");
3214-
} catch (CBORException ex2) {
3212+
} catch (CBORException ex) {
32153213
// NOTE: Intentionally empty
3216-
} catch (Exception ex2) {
3217-
Assert.fail(ex2.toString());
3218-
throw new IllegalStateException("", ex2);
3214+
} catch (Exception ex3) {
3215+
Assert.fail(ex3.toString());
3216+
throw new IllegalStateException("", ex3);
32193217
}
32203218
}
32213219
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.upokecenter.test;
2+
/*
3+
Written by Peter O. in 2014.
4+
Any copyright is dedicated to the Public Domain.
5+
http://creativecommons.org/publicdomain/zero/1.0/
6+
If you like this, you should donate to Peter O.
7+
at: http://peteroupc.github.io/
8+
*/
9+
10+
public final class FieldClass {
11+
public int publicFieldA;
12+
public final int ReadonlyFieldA = 33;
13+
private int PrivateFieldA;
14+
private final int PrivateFieldB = 44;
15+
}

src/test/java/com/upokecenter/test/ToObjectTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,13 +1103,6 @@ public void TestAsString() {
11031103
}
11041104
}
11051105

1106-
private static final class FieldClass {
1107-
public int PublicFieldA;
1108-
public final int ReadonlyFieldA = 33;
1109-
private int privateFieldA;
1110-
private final int privateFieldB = 44;
1111-
private static int staticFieldA;
1112-
}
11131106

11141107
@Test
11151108
public void TestToObjectFieldClass() {
@@ -1145,7 +1138,7 @@ public void TestToObjectFieldClass() {
11451138
co.set("privateFieldA",ToObjectTest.TestToFromObjectRoundTrip(999));
11461139
co.set("publicFieldA",ToObjectTest.TestToFromObjectRoundTrip(999));
11471140
fc = (FieldClass)co.ToObject(FieldClass.class);
1148-
Assert.assertEquals(999, fc.PublicFieldA);
1141+
Assert.assertEquals(999, fc.publicFieldA);
11491142
}
11501143

11511144
@Test(timeout = 5000)

0 commit comments

Comments
 (0)