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
ByteBuffer corrupted by ByteBufferConverter when passed through Spring [SPR-13056] #17648
Comments
Juergen Hoeller commented This doesn't seem to be a bug in I assume you're experiencing this issue through Spring Integration? If so, I'd suggest raising it with those guys on their JIRA, since the extraction of a single element probably happens somewhere in the specific conversion handling. If the root of the problem turns out to be in the core Juergen |
Nathan Hull commented I just attached sources for a dummy project that demonstrates the bug. All it does is send a ByteBuffer via a gateway to a service activator. I don't know how to tell if it's a problem in core or integration. |
Juergen Hoeller commented I've moved this over to Spring Integration since that's the better starting point for an analysis here... Juergen |
Artem Bilan commented Juergen Hoeller, I've just done this test: public class Int3720Tests {
@Test
public void testIt() {
TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(ByteBuffer.class);
ByteBuffer byteBuffer = ByteBuffer.allocate(2);
byteBuffer.put((byte) 1);
byteBuffer.put((byte) 2);
byteBuffer.rewind();
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Context.class);
ConversionService conversionService = context.getBean(ConversionService.class);
Object result = conversionService.convert(byteBuffer, typeDescriptor, typeDescriptor);
assertEquals(byteBuffer, result);
byteBuffer.rewind();
ConfigurableApplicationContext intContext = new AnnotationConfigApplicationContext(IntegrationContext.class);
ConversionService intConversionService = intContext.getBean(ConversionService.class);
result = intConversionService.convert(byteBuffer, typeDescriptor, typeDescriptor);
assertEquals(byteBuffer, result);
context.close();
intContext.close();
}
@Configuration
@EnableIntegration
public static class IntegrationContext {
}
@Configuration
public static class Context {
@Bean
public FactoryBean<ConversionService> conversionService() {
return new ConversionServiceFactoryBean();
}
}
} And it really shows me that From my perspective we must not even try to convert if the Would you mind sharing your test-case to take a look ? Thanks! |
Juergen Hoeller commented Artem Bilan, I was just using this one:
Looking at your test case, you seem to reuse the original |
Artem Bilan commented Thank you, Juergen, but doesn't work even like this: byte[] bytes = new byte[] { 1, 2, 3 };
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Context.class);
ConversionService conversionService = context.getBean(ConversionService.class);
ByteBuffer result = conversionService.convert(byteBuffer, ByteBuffer.class);
assertThat(result, equalTo(ByteBuffer.wrap(bytes)));
We can't bypass I am on the SF-4.2.0.BULD-SNAPSHOT. Come back to you later, when I fix some my own issue and prepare a raw test-case just for Thank you for your time anyway! |
Juergen Hoeller commented I've found the key difference in the tests: Our I'll have a look at the Juergen |
Nathan Hull commented The logic around the call to |
Juergen Hoeller commented We intentionally create an independent copy of the Generally speaking, the root of the problem was that Juergen |
Juergen Hoeller commented This is now in master and will be available in the upcoming Juergen |
Artem Bilan commented Thanks, Juergen! Works well now. |
Nathan Hull opened SPR-13056 and commented
It looks like spring-core 4.x has a bug in how it handles a ByteBuffer being sent on a Spring channel. It converts the ByteBuffer to a byte array, then takes the first element of that array, converts that to a byte array, and then wraps that byte array in a new ByteBuffer. As a result, when I pass a ByteBuffer on a Spring channel, I get a different ByteBuffer out and it only contains the first element, if the ByteBuffer had one or more elements remaining. Most of this happens in ByteBufferConverter.
Attachments:
Referenced from: commits 792b7b9, 1177f5c, 008c9a3, fee63fd
The text was updated successfully, but these errors were encountered: