@Test public void testAddCatalogue_MultiThreads_shouldWork() throws Exception { final boolean[] threwException = new boolean[3]; Thread thread1 = new Thread( new Runnable() { @Override public void run() { try { Registry.addCatalogue("catalogue", new Catalogue1()); threwException[0] = false; } catch (GeneralSecurityException e) { threwException[0] = true; } } }); Thread thread2 = new Thread( new Runnable() { @Override public void run() { try { Registry.addCatalogue("catalogue", new Catalogue2()); threwException[1] = false; } catch (GeneralSecurityException e) { threwException[1] = true; } } }); Thread thread3 = new Thread( new Runnable() { @Override public void run() { try { Registry.addCatalogue("catalogue", new Catalogue3()); threwException[2] = false; } catch (GeneralSecurityException e) { threwException[2] = true; } } }); thread1.start(); thread2.start(); thread3.start(); thread1.join(); thread2.join(); thread3.join(); int count = 0; for (int i = 0; i < 3; i++) { if (threwException[i]) { count++; } } assertThat(count).isEqualTo(2); }
@Deprecated public static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue) throws GeneralSecurityException { if (catalogueName == null) { throw new IllegalArgumentException("catalogueName must be non-null."); } if (catalogue == null) { throw new IllegalArgumentException("catalogue must be non-null."); } if (catalogueMap.containsKey(catalogueName.toLowerCase(Locale.US))) { Catalogue<?> existing = catalogueMap.get(catalogueName.toLowerCase(Locale.US)); if (!catalogue.getClass().equals(existing.getClass())) { logger.warning( "Attempted overwrite of a catalogueName catalogue for name " + catalogueName); throw new GeneralSecurityException( "catalogue for name " + catalogueName + " has been already registered"); } } catalogueMap.put(catalogueName.toLowerCase(Locale.US), catalogue); }
Registry { @Deprecated public static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue) throws GeneralSecurityException { if (catalogueName == null) { throw new IllegalArgumentException("catalogueName must be non-null."); } if (catalogue == null) { throw new IllegalArgumentException("catalogue must be non-null."); } if (catalogueMap.containsKey(catalogueName.toLowerCase(Locale.US))) { Catalogue<?> existing = catalogueMap.get(catalogueName.toLowerCase(Locale.US)); if (!catalogue.getClass().equals(existing.getClass())) { logger.warning( "Attempted overwrite of a catalogueName catalogue for name " + catalogueName); throw new GeneralSecurityException( "catalogue for name " + catalogueName + " has been already registered"); } } catalogueMap.put(catalogueName.toLowerCase(Locale.US), catalogue); } }
Registry { @Deprecated public static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue) throws GeneralSecurityException { if (catalogueName == null) { throw new IllegalArgumentException("catalogueName must be non-null."); } if (catalogue == null) { throw new IllegalArgumentException("catalogue must be non-null."); } if (catalogueMap.containsKey(catalogueName.toLowerCase(Locale.US))) { Catalogue<?> existing = catalogueMap.get(catalogueName.toLowerCase(Locale.US)); if (!catalogue.getClass().equals(existing.getClass())) { logger.warning( "Attempted overwrite of a catalogueName catalogue for name " + catalogueName); throw new GeneralSecurityException( "catalogue for name " + catalogueName + " has been already registered"); } } catalogueMap.put(catalogueName.toLowerCase(Locale.US), catalogue); } private  Registry(); }
Registry { @Deprecated public static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue) throws GeneralSecurityException { if (catalogueName == null) { throw new IllegalArgumentException("catalogueName must be non-null."); } if (catalogue == null) { throw new IllegalArgumentException("catalogue must be non-null."); } if (catalogueMap.containsKey(catalogueName.toLowerCase(Locale.US))) { Catalogue<?> existing = catalogueMap.get(catalogueName.toLowerCase(Locale.US)); if (!catalogue.getClass().equals(existing.getClass())) { logger.warning( "Attempted overwrite of a catalogueName catalogue for name " + catalogueName); throw new GeneralSecurityException( "catalogue for name " + catalogueName + " has been already registered"); } } catalogueMap.put(catalogueName.toLowerCase(Locale.US), catalogue); } private  Registry(); @Deprecated static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue); @Deprecated static Catalogue<?> getCatalogue(String catalogueName); static synchronized void registerKeyManager(final KeyManager<P> manager); static synchronized void registerKeyManager(
      final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerKeyManager(
      final KeyTypeManager<KeyProtoT> manager, boolean newKeyAllowed); static synchronized void registerAsymmetricKeyManagers(
          final PrivateKeyTypeManager<KeyProtoT, PublicKeyProtoT> privateKeyTypeManager,
          final KeyTypeManager<PublicKeyProtoT> publicKeyTypeManager,
          boolean newKeyAllowed); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerPrimitiveWrapper(
      final PrimitiveWrapper<B, P> wrapper); @Deprecated static KeyManager<P> getKeyManager(String typeUrl); static KeyManager<?> getUntypedKeyManager(String typeUrl); static KeyManager<P> getKeyManager(String typeUrl, Class<P> primitiveClass); static synchronized KeyData newKeyData(KeyTemplate keyTemplate); static synchronized MessageLite newKey(KeyTemplate keyTemplate); static synchronized MessageLite newKey(String typeUrl, MessageLite format); static KeyData getPublicKeyData(String typeUrl, ByteString serializedPrivateKey); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, MessageLite key); static P getPrimitive(String typeUrl, MessageLite key, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, ByteString serializedKey); static P getPrimitive(
      String typeUrl, ByteString serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, byte[] serializedKey); static P getPrimitive(String typeUrl, byte[] serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(KeyData keyData); static P getPrimitive(KeyData keyData, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(KeysetHandle keysetHandle); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager, Class<P> primitiveClass); static P wrap(PrimitiveSet<B> primitiveSet, Class<P> clazz); static P wrap(PrimitiveSet<P> primitiveSet); static Class<?> getInputPrimitive(Class<?> wrappedPrimitive); }
Registry { @Deprecated public static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue) throws GeneralSecurityException { if (catalogueName == null) { throw new IllegalArgumentException("catalogueName must be non-null."); } if (catalogue == null) { throw new IllegalArgumentException("catalogue must be non-null."); } if (catalogueMap.containsKey(catalogueName.toLowerCase(Locale.US))) { Catalogue<?> existing = catalogueMap.get(catalogueName.toLowerCase(Locale.US)); if (!catalogue.getClass().equals(existing.getClass())) { logger.warning( "Attempted overwrite of a catalogueName catalogue for name " + catalogueName); throw new GeneralSecurityException( "catalogue for name " + catalogueName + " has been already registered"); } } catalogueMap.put(catalogueName.toLowerCase(Locale.US), catalogue); } private  Registry(); @Deprecated static synchronized void addCatalogue(String catalogueName, Catalogue<?> catalogue); @Deprecated static Catalogue<?> getCatalogue(String catalogueName); static synchronized void registerKeyManager(final KeyManager<P> manager); static synchronized void registerKeyManager(
      final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerKeyManager(
      final KeyTypeManager<KeyProtoT> manager, boolean newKeyAllowed); static synchronized void registerAsymmetricKeyManagers(
          final PrivateKeyTypeManager<KeyProtoT, PublicKeyProtoT> privateKeyTypeManager,
          final KeyTypeManager<PublicKeyProtoT> publicKeyTypeManager,
          boolean newKeyAllowed); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager); @Deprecated static synchronized void registerKeyManager(
      String typeUrl, final KeyManager<P> manager, boolean newKeyAllowed); static synchronized void registerPrimitiveWrapper(
      final PrimitiveWrapper<B, P> wrapper); @Deprecated static KeyManager<P> getKeyManager(String typeUrl); static KeyManager<?> getUntypedKeyManager(String typeUrl); static KeyManager<P> getKeyManager(String typeUrl, Class<P> primitiveClass); static synchronized KeyData newKeyData(KeyTemplate keyTemplate); static synchronized MessageLite newKey(KeyTemplate keyTemplate); static synchronized MessageLite newKey(String typeUrl, MessageLite format); static KeyData getPublicKeyData(String typeUrl, ByteString serializedPrivateKey); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, MessageLite key); static P getPrimitive(String typeUrl, MessageLite key, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, ByteString serializedKey); static P getPrimitive(
      String typeUrl, ByteString serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(String typeUrl, byte[] serializedKey); static P getPrimitive(String typeUrl, byte[] serializedKey, Class<P> primitiveClass); @Deprecated @SuppressWarnings("TypeParameterUnusedInFormals") static P getPrimitive(KeyData keyData); static P getPrimitive(KeyData keyData, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(KeysetHandle keysetHandle); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, Class<P> primitiveClass); @Deprecated static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager); static PrimitiveSet<P> getPrimitives(
      KeysetHandle keysetHandle, final KeyManager<P> customManager, Class<P> primitiveClass); static P wrap(PrimitiveSet<B> primitiveSet, Class<P> clazz); static P wrap(PrimitiveSet<P> primitiveSet); static Class<?> getInputPrimitive(Class<?> wrappedPrimitive);  }