infinispan / infinispan/protostream

Protobuf encoding marshling is not working when in a Java collection is used in the value part of the map

Open
#182 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
56
Forks
39
Avg merge
5h 36m
Merged PRs (30d)
5

Description

Hi

With the following cache definition e.g: `Cache>` , with Protobuf, the values are not being marshalled.

To recreated this issue, you can create a new project:

```bash
mvn archetype:generate -DarchetypeGroupId=org.infinispan.archetypes -DarchetypeArtifactId=embedded -DarchetypeVersion=14.0.1.Final
```

added the latest lib in the pom.xml:

```xml
...

org.infinispan.protostream
protostream-processor
14.0.0.CR2

...
```

Edited the upd xml file:

```xml




test.com.Sensor







```
A very simple POJO

```java
public class Sensor {

@ProtoField(value = 1, defaultValue = "0")
public int anInt;

public Sensor() {
}

public Sensor(int anInt) {
this.anInt = anInt;
}
}
```

This code:

```java
public void basicUse() {
System.out.println("\n\n1. Demonstrating basic usage of Infinispan. This cache stores arbitrary Strings.");
Cache> cache = cacheManager.getCache("stockTickers", true);

cache.put("test", new ArrayList<>(List.of(new Sensor(1), new Sensor(2), new Sensor(3), new Sensor(4))));

// this fails
List test = cache.get("test");

}
```

yields in: **Exception in thread "main" org.infinispan.commons.dataconversion.EncodingException: ISPN000495: ProtostreamTranscoder encountered error transcoding content** because in this [code](https://github.com/infinispan/protostream/blob/main/core/src/main/java/org/infinispan/protostream/WrappedMessage.java#L528), since in the example the array contains 4elements (4tags and 4 bytes arrays), the field count gives 8, throwing the error. If you only add one into the list the code works:

```java
//this works
cache.put("test", new ArrayList<>(List.of(new Sensor(1))));
```

I've tried simple types, like a list of integers `Cache>` and it works because of the break in the switch

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Maven embedded project reproduction and inspect WrappedMessage.java at the linked code location, comparing a list containing one Sensor with one containing four. Verify the ProtoStream cache configuration and reproduce the EncodingException with Cache>. Done means multi-element Sensor collections are retrieved without the field-count error and retain their values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.