Skip to content

Commit

Permalink
Replicas of dummy encodings should also be dummy encodings.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Mar 20, 2015
1 parent 6b60d54 commit 7c0d57e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/org/jcodings/EncodingDB.java
Expand Up @@ -171,13 +171,20 @@ public static void alias(String alias, String original) {
}

public static void replicate(String replica, String original) {
replicate(replica, original, false);
byte[]origBytes = original.getBytes();
Entry originalEntry = encodings.get(origBytes);
if (originalEntry == null) throw new InternalException(ErrorMessages.ERR_NO_SUCH_ENCODNG, original);
finishReplica(replica, originalEntry.isDummy, originalEntry);
}

private static void replicate(String replica, String original, boolean dummy) {
byte[]origBytes = original.getBytes();
Entry originalEntry = encodings.get(origBytes);
if (originalEntry == null) throw new InternalException(ErrorMessages.ERR_NO_SUCH_ENCODNG, original);
finishReplica(replica, dummy, originalEntry);
}

private static void finishReplica(String replica, boolean dummy, Entry originalEntry) {
byte[]replicaBytes = replica.getBytes();
if (encodings.get(replicaBytes) != null) throw new InternalException(ErrorMessages.ERR_ENCODING_REPLICA_ALREADY_REGISTERED, replica);
encodings.putDirect(replicaBytes, new Entry(replicaBytes, originalEntry, dummy));
Expand Down

0 comments on commit 7c0d57e

Please sign in to comment.