Source:
public Key(K2Context context, KeyData data) throws UnregisteredKeyVersionException, InvalidKeyDataException { KeyVersionRegistry registry = context.getKeyVersionRegistry(); ExtensionRegistry protoRegistry = registry.getProtoExtensions(); coreBytes = data.getCore(); @SuppressWarnings("unused") KeyCore core; try { core = KeyCore.parseFrom(coreBytes, protoRegistry); } catch (InvalidProtocolBufferException ex) { throw new InvalidKeyDataException( InvalidKeyDataException.Reason.PROTO_PARSE, ex); } final int kvCount = data.getKeyVersionCount(); keyVersions.ensureCapacity(kvCount); UnregisteredKeyVersionException unregisteredException = null; InvalidKeyDataException buildException = null; for (KeyVersionData kvData : data.getKeyVersionList()) { try { KeyVersion kv = registry.newBuilder(kvData.getType()) .withData(kvData, protoRegistry).build(); keyVersions.add(kv); } catch (InvalidProtocolBufferException ex) { throw new InvalidKeyDataException( InvalidKeyDataException.Reason.PROTO_PARSE, ex); } catch (BuilderException ex) { buildException = new InvalidKeyDataException( InvalidKeyDataException.Reason.KEY_VERSION_BUILD, ex); } catch (UnregisteredKeyVersionException ex) { unregisteredException = ex; } } if (unregisteredException != null) { throw unregisteredException; } else if (buildException != null) { throw buildException; } if (kvCount > 0) { int primaryIndex = (data.hasPrimary() ? data.getPrimary() : -1); if (primaryIndex < 0 || primaryIndex >= keyVersions.size()) { throw new InvalidKeyDataException( InvalidKeyDataException.Reason.CORRUPTED_PRIMARY, null); } primary = keyVersions.get(primaryIndex); } }

Target:
public Key(K2Context context, KeyData data) throws UnregisteredKeyVersionException, InvalidKeyDataException { KeyVersionRegistry registry = context.getKeyVersionRegistry(); ExtensionRegistry protoRegistry = registry.getProtoExtensions(); coreBytes = data.getCore(); KeyCore core; try { core = KeyCore.parseFrom(coreBytes, protoRegistry); } catch (InvalidProtocolBufferException ex) { throw new InvalidKeyDataException( InvalidKeyDataException.Reason.PROTO_PARSE, ex); } final int kvCount = data.getKeyVersionCount(); keyVersions.ensureCapacity(kvCount); UnregisteredKeyVersionException unregisteredException = null; InvalidKeyDataException buildException = null; for (KeyVersionData kvData : data.getKeyVersionList()) { try { KeyVersion kv = registry.newBuilder(kvData.getType()) .withData(kvData, protoRegistry).build(); keyVersions.add(kv); } catch (InvalidProtocolBufferException ex) { throw new InvalidKeyDataException( InvalidKeyDataException.Reason.PROTO_PARSE, ex); } catch (BuilderException ex) { buildException = new InvalidKeyDataException( InvalidKeyDataException.Reason.KEY_VERSION_BUILD, ex); } catch (UnregisteredKeyVersionException ex) { unregisteredException = ex; } } if (unregisteredException != null) { throw unregisteredException; } else if (buildException != null) { throw buildException; } if (kvCount > 0) { int primaryIndex = (data.hasPrimary() ? data.getPrimary() : -1); if (primaryIndex < 0 || primaryIndex >= keyVersions.size()) { throw new InvalidKeyDataException( InvalidKeyDataException.Reason.CORRUPTED_PRIMARY, null); } primary = keyVersions.get(primaryIndex); } }