# Why am I getting this \`unexpected byte \[0x10\]\` in the constructor for a custom PluginBuilder?

**URL:** <https://discuss.elastic.co/t/why-am-i-getting-this-unexpected-byte-0x10-in-the-constructor-for-a-custom-pluginbuilder/151760>\
**Category:** Elasticsearch\
**Created:** [October 10, 2018, 6:42am UTC](https://discuss.elastic.co/t/why-am-i-getting-this-unexpected-byte-0x10-in-the-constructor-for-a-custom-pluginbuilder/151760 "2018-10-10T06:42:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brett\_Anderson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brett_anderson/32/2555_2.png) [@Brett\_Anderson](https://discuss.elastic.co/u/Brett_Anderson)\
**Post date:** [October 10, 2018, 6:42am UTC](https://discuss.elastic.co/t/why-am-i-getting-this-unexpected-byte-0x10-in-the-constructor-for-a-custom-pluginbuilder/151760/1 "2018-10-10T06:42:09Z")

</div>

Using Elasticsearch 5.6.5 I'm getting the following strange error:

> org.elasticsearch.transport.RemoteTransportException: [iad1esdn20vz166][x.x.x.x:31203][indices:data/read/search[phase/query]]  
> Caused by: java.lang.IllegalStateException: unexpected byte [0x10]  
> at org.elasticsearch.common.io.stream.StreamInput.readBoolean(StreamInput.java:409) ~[elasticsearch-5.6.5.jar:5.6.5]  
> at org.elasticsearch.common.io.stream.StreamInput.readBoolean(StreamInput.java:399) ~[elasticsearch-5.6.5.jar:5.6.5]  
> at org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder.read(ValuesSourceAggregationBuilder.java:119) ~[elasticsearch-5.6.5.jar:5.6.5]  
> at org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder.(ValuesSourceAggregationBuilder.java:99) ~[elasticsearch-5.6.5.jar:5.6.5]  
> at org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder$LeafOnly.(ValuesSourceAggregationBuilder.java:53) ~[elasticsearch-5.6.5.jar:5.6.5]  
> at com.foo.elasticsearch.VectorAggregationPluginBuilder.(VectorAggregationPluginBuilder.java:88) ~[?:?]  
> ...

Can anyone see anything that I'm obviously doing wrong with my plugin? The error is thrown at the line: super(in, ValuesSourceType.BYTES, ValueType.STRING); - and then you can see the stack trace above from that point to line 119 in org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder

```
public class VectorAggregationPluginBuilder extends ValuesSourceAggregationBuilder.LeafOnly<ValuesSource.Bytes, VectorAggregationPluginBuilder> {
    public static final String NAME = "vector_avg";

    public static final ParseField ENCODED_QUERY_VECTOR_FIELD = new ParseField("encoded_vector");
    public static final ParseField USE_COSINE_FIELD = new ParseField("cosine");

    private static final ObjectParser<VectorAggregationPluginBuilder, QueryParseContext> PARSER;

    private String encodedQueryVector = null;
    private double[] queryVector = null;
    private double magnitude = 0;
    private boolean useCosine = false;

    static {
        PARSER = new ObjectParser<>(VectorAggregationPluginBuilder.NAME);
        ValuesSourceParserHelper.declareBytesFields(PARSER, false, false);
        PARSER.declareStringOrNull(VectorAggregationPluginBuilder::encodedQueryVector, VectorAggregationPluginBuilder.ENCODED_QUERY_VECTOR_FIELD);
        PARSER.declareBoolean(VectorAggregationPluginBuilder::useCosine, VectorAggregationPluginBuilder.USE_COSINE_FIELD);
    }

    public static AggregationBuilder parse(String aggregationName, QueryParseContext context) throws IOException {
        return PARSER.parse(context.parser(), new VectorAggregationPluginBuilder(aggregationName), context);
    }

    public VectorAggregationPluginBuilder(String name) {
        super(name, ValuesSourceType.BYTES, ValueType.STRING);
    }

    /**
     * Read from a stream.
     */
    public VectorAggregationPluginBuilder(StreamInput in) throws IOException {
        super(in, ValuesSourceType.BYTES, ValueType.STRING);
        encodedQueryVector = in.readOptionalString();
        if (encodedQueryVector != null) {
            queryVector = Util.convertBase64ToArray(encodedQueryVector);
        }
        Boolean useCosineNullable = in.readOptionalBoolean();
        if (useCosineNullable != null){
            useCosine = useCosineNullable.booleanValue();
        }
    }

    @Override
    protected void innerWriteTo(StreamOutput out) throws IOException {
        out.writeOptionalString(encodedQueryVector);
        out.writeOptionalBoolean(new Boolean(useCosine));
    }

    @Override
    protected boolean serializeTargetValueType() {
        return true;
    }

    public VectorAggregationPluginBuilder encodedQueryVector(String encodedQueryVector) {
        if (encodedQueryVector != null){
            this.encodedQueryVector = encodedQueryVector;
        }
        return this;
    }

    public String encodedQueryVector() {
        if (encodedQueryVector != null){
            return encodedQueryVector;
        }
        return null;
    }

    public VectorAggregationPluginBuilder useCosine(boolean useCosine) {
        this.useCosine = useCosine;
        return this;
    }

    public boolean useCosine() {
        return useCosine;
    }

    @Override
    protected VectorAggregationFactory innerBuild(SearchContext context, ValuesSourceConfig<ValuesSource.Bytes> config,
            AggregatorFactory<?> parent, Builder subFactoriesBuilder) throws IOException {
        return new VectorAggregationFactory(name, config, queryVector, useCosine, magnitude, context, parent, subFactoriesBuilder, metaData);
    }

    @Override
    public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
        if (encodedQueryVector != null) {
            builder.field(ENCODED_QUERY_VECTOR_FIELD.getPreferredName(), encodedQueryVector);
        }
        builder.field(USE_COSINE_FIELD.getPreferredName(), useCosine);
        return builder;
    }

    @Override
    protected int innerHashCode() {
        return Objects.hash(useCosine, encodedQueryVector);
    }

    @Override
    protected boolean innerEquals(Object obj) {
        VectorAggregationPluginBuilder other = (VectorAggregationPluginBuilder) obj;
        return Objects.equals(encodedQueryVector, other.encodedQueryVector) &&
            Objects.equals(useCosine, other.useCosine);
    }

    @Override
    public String getType() {
        return NAME;
    }
}

```

---

<div class="post-metadata">

**Author:** ![Brett\_Anderson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brett_anderson/32/2555_2.png) [@Brett\_Anderson](https://discuss.elastic.co/u/Brett_Anderson)\
**Post date:** [October 11, 2018, 8:53pm UTC](https://discuss.elastic.co/t/why-am-i-getting-this-unexpected-byte-0x10-in-the-constructor-for-a-custom-pluginbuilder/151760/2 "2018-10-11T20:53:45Z")

</div>

The problem was the line `super(in, ValuesSourceType.BYTES, ValueType.STRING);` It should have been `super(in, ValuesSourceType.BYTES);`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 8, 2018, 8:53pm UTC](https://discuss.elastic.co/t/why-am-i-getting-this-unexpected-byte-0x10-in-the-constructor-for-a-custom-pluginbuilder/151760/3 "2018-11-08T20:53:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
