Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientConfigXmlGenerator.generate(clientConfig) widens type class for serializer #16047

Closed
neilstevenson opened this issue Nov 18, 2019 · 3 comments

Comments

@neilstevenson
Copy link
Contributor

@neilstevenson neilstevenson commented Nov 18, 2019

On 4.0-BETA-1, if a StreamSerializer is added using setTypeClass instead of setTypeClassName, this is not correctly handled.

If setTypeClass(Xxx.class) is used, this is converted to a String as java.lang.Class by ClientConfigXmlGenerator.generate(clientConfig); so cannot be used.

Reproducer:

public class Main {

	public static void main(String[] args) throws Exception {
		
		ClientConfig beforeClientConfig = new ClientConfig();
		
        SerializerConfig beforeSerializerConfig1 = new SerializerConfig();
        beforeSerializerConfig1.setClass(MySerializer1.class);
        beforeSerializerConfig1.setTypeClass(MyType1.class);
        SerializerConfig beforeSerializerConfig2 = new SerializerConfig();
        beforeSerializerConfig2.setClassName(MySerializer2.class.getName());
        beforeSerializerConfig2.setTypeClassName(MyType2.class.getName());
        SerializerConfig beforeSerializerConfig3 = new SerializerConfig();
        beforeSerializerConfig3.setImplementation(new MySerializer3());
        beforeSerializerConfig3.setTypeClass(MyType1.class);

        beforeClientConfig.getSerializationConfig().addSerializerConfig(beforeSerializerConfig1);
        beforeClientConfig.getSerializationConfig().addSerializerConfig(beforeSerializerConfig2);
        beforeClientConfig.getSerializationConfig().addSerializerConfig(beforeSerializerConfig3);

        System.out.println("BEFORE");
        System.out.println(beforeClientConfig.getSerializationConfig().getSerializerConfigs());
        
		String during = ClientConfigXmlGenerator.generate(beforeClientConfig);
		System.out.println("DURING");
		System.out.println(during);
		
		ByteArrayInputStream inputStream = new ByteArrayInputStream(during.getBytes(StandardCharsets.UTF_8));
		
		ClientConfig afterClientConfig = new XmlClientConfigBuilder(inputStream).build();

		System.out.println("AFTER");
		System.out.println(afterClientConfig.getSerializationConfig().getSerializerConfigs());
		
		inputStream.close();
	}
	
	@SuppressWarnings("rawtypes")
	static class MySerializer1 implements StreamSerializer {
		@Override
		public int getTypeId() {
			return 0;
		}
		@Override
		public void destroy() {
		}
		@Override
		public void write(ObjectDataOutput out, Object object) throws IOException {
		}

		@Override
		public Object read(ObjectDataInput in) throws IOException {
			return null;
		}}
	@SuppressWarnings("rawtypes")
	static class MySerializer2 implements StreamSerializer {
		@Override
		public int getTypeId() {
			return 0;
		}
		@Override
		public void destroy() {
		}
		@Override
		public void write(ObjectDataOutput out, Object object) throws IOException {
		}

		@Override
		public Object read(ObjectDataInput in) throws IOException {
			return null;
		}}
	@SuppressWarnings("rawtypes")
	static class MySerializer3 implements StreamSerializer {
		@Override
		public int getTypeId() {
			return 0;
		}
		@Override
		public void destroy() {
		}
		@Override
		public void write(ObjectDataOutput out, Object object) throws IOException {
		}

		@Override
		public Object read(ObjectDataInput in) throws IOException {
			return null;
		}}
	static class MyType1 {}
	static class MyType2 {}
	static class MyType3 {}

}
@neilstevenson

This comment has been minimized.

Copy link
Contributor Author

@neilstevenson neilstevenson commented Nov 18, 2019

This is the faulty line - https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/client/config/ClientConfigXmlGenerator.java#L307

The server side equivalent is correct I think - https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/config/ConfigXmlGenerator.java#L459

SerializedConfig.getTypeClass returns the class

Both sides should return class.getName().
Client side is effectively doing class.getClass().getName()

@sancar

This comment has been minimized.

Copy link
Member

@sancar sancar commented Dec 2, 2019

fixed via #16097

@sancar sancar closed this Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.