/** * Registers a {@code DataSerializer} instance with the data serialization framework. * * @param distribute Should the registered {@code DataSerializer} be distributed to other members * of the distributed system? * @see DataSerializer#register(Class) */ public static DataSerializer register(Class c, boolean distribute) { final DataSerializer s = newInstance(c); return _register(s, distribute); }
public static DataSerializer register(Class c, boolean distribute, EventID eventId, ClientProxyMembershipID context) { DataSerializer s = newInstance(c); // This method is only called when server connection and CacheClientUpdaterThread s.setEventId(eventId); s.setContext(context); return _register(s, distribute); }
s = newInstance(c); } catch (IllegalArgumentException ex) {
@Test public void testHandshakeDatSerializerRegistrationDoesNotHitNPE() throws Throwable { // a thread performing a handshake from the client side may receive a list of // DataSerializer class names. It registers these with InternalDataSerializer to // create placeholders for later lazy loading of the classes Class[] serializers = new Class[] {DataSerializer1.class, DataSerializer2.class, DataSerializer3.class, DataSerializer4.class, DataSerializer5.class, DataSerializer6.class, DataSerializer7.class, DataSerializer8.class, DataSerializer9.class, DataSerializer10.class, DataSerializer11.class, DataSerializer12.class, DataSerializer13.class}; for (int index = 0; index < serializers.length; index++) { int id = InternalDataSerializer.newInstance(serializers[index]).getId(); InternalDataSerializer.register(serializers[index].getName(), false, null, null, id); } // The thread will then register classes handled by the DataSerializers, but if // getSerializers() or a similar method is invoked by some other thread first the // placeholders will be wiped out, causing an NPE when registering the handled // classes. The NPE is caused by the placeholder being null in updateSupportedClassesMap(). // Here we avoid creating a multithreaded test by invoking getSerializers() in-line InternalDataSerializer.getSerializers(); // Now we perform the second step in the handshake code of registering the classes // handled by the DataSerializers. Without the bugfix this causes an NPE Map<Integer, List<String>> supportedClasses = new HashMap<>(); for (int index = 0; index < serializers.length; index++) { DataSerializer serializer = InternalDataSerializer.newInstance(serializers[index]); List<String> classes = Arrays.<Class>asList(serializer.getSupportedClasses()).stream() .map((clazz) -> clazz.getName()).collect(Collectors.toList()); supportedClasses.put(serializer.getId(), classes); } InternalDataSerializer.updateSupportedClassesMap(supportedClasses); }