# TagHistoryManager().queryHistory : java.lang.IllegalArgumentException: Comparison method violates its general contract!

**URL:** <https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206>\
**Category:** Module Development\
**Tags:** ignition80\
**Created:** [December 4, 2020, 2:05pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206 "2020-12-04T14:05:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [December 4, 2020, 2:05pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/1 "2020-12-04T14:05:24Z")

</div>

**Ignition 8.1.0**

I use **TagHistoryManager().queryHistory** to retrieve some history data from a module (gateway scope)

Sometimes, I have the following exception:

```auto
ResultWriter	03Dec2020 16:20:20	Error executing historical tag read.
java.lang.IllegalArgumentException: Comparison method violates its general contract!

```

what does it mean ?

```auto
            BasicTagHistoryQueryParams tagHistoryQueryParams = new BasicTagHistoryQueryParams();
            // /!\ Flag.and() doesn't mutate the object, it returns a new one
            Flags flags = Flags.of(TagHistoryQueryFlags.BOUNDING_VALUES_YES,
                    TagHistoryQueryFlags.NO_INTERPOLATION,
                    TagHistoryQueryFlags.NO_SCANCLASS_VALIDATION,
                    TagHistoryQueryFlags.NO_CACHE,
                    TagHistoryQueryFlags.NO_PREPROCESSED_DATA);

            tagHistoryQueryParams.setQueryFlags(flags);
            tagHistoryQueryParams.setReturnSize(-1);
            tagHistoryQueryParams.setAggregationMode(AggregationMode.LastValue);
            tagHistoryQueryParams.setStartDate(startDate);
            tagHistoryQueryParams.setEndDate(endDate);
            // Tall : Column format is fixed at "path, value, quality, timestamp".
            tagHistoryQueryParams.setReturnFormat(ReturnFormat.Tall);
            tagHistoryQueryParams.setPaths(paths);
            BasicStreamingDataset streamingDataset = new BasicStreamingDataset();
            logger.debug("queryHistoryDataChanges() - begin");

            this.gatewayContext.getTagHistoryManager().queryHistory(tagHistoryQueryParams, streamingDataset);

```

```auto
ResultWriter	03Dec2020 16:20:20	Error executing historical tag read.
java.lang.IllegalArgumentException: Comparison method violates its general contract!

at java.base/java.util.ComparableTimSort.mergeHi(Unknown Source)

at java.base/java.util.ComparableTimSort.mergeAt(Unknown Source)

at java.base/java.util.ComparableTimSort.mergeCollapse(Unknown Source)

at java.base/java.util.ComparableTimSort.sort(Unknown Source)

at java.base/java.util.Arrays.sort(Unknown Source)

at java.base/java.util.Arrays.sort(Unknown Source)

at java.base/java.util.ArrayList.sort(Unknown Source)

at java.base/java.util.Collections.sort(Unknown Source)

at com.inductiveautomation.gateway.tags.history.query.DatasourceQueryExecutor.runSpecialValueQuery(DatasourceQueryExecutor.java:864)

at com.inductiveautomation.gateway.tags.history.query.DatasourceQueryExecutor.readSeedValues(DatasourceQueryExecutor.java:699)

at com.inductiveautomation.gateway.tags.history.query.DatasourceQueryExecutor.primeRead(DatasourceQueryExecutor.java:885)

at com.inductiveautomation.ignition.gateway.sqltags.history.query.AbstractHistoryLoader.startReading(AbstractHistoryLoader.java:118)

at com.inductiveautomation.ignition.gateway.sqltags.history.query.AggregateHistoryQueryExecutor.startReading(AggregateHistoryQueryExecutor.java:85)

at com.inductiveautomation.ignition.gateway.sqltags.history.query.HistoryWriter.readData(HistoryWriter.java:312)

at com.inductiveautomation.ignition.gateway.sqltags.history.query.HistoryWriter.execute(HistoryWriter.java:230)

at com.inductiveautomation.ignition.gateway.sqltags.history.TagHistoryManagerImpl.queryHistory(TagHistoryManagerImpl.java:538)

at com.bouyguesenergiesservices.ignition.gateway.replay.tag.QueryHistoryTall.queryHistoryDataChanges(QueryHistoryTall.java:1108)

at com.bouyguesenergiesservices.ignition.gateway.replay.tag.QueryHistoryTall.queryHistory(QueryHistoryTall.java:886)

at com.bouyguesenergiesservices.ignition.gateway.replay.tag.QueryHistoryTall.lambda$queryHistoryAsync$0(QueryHistoryTall.java:170)

at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)

at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.exec(Unknown Source)

at java.base/java.util.concurrent.ForkJoinTask.doExec(Unknown Source)

at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(Unknown Source)

at java.base/java.util.concurrent.ForkJoinPool.scan(Unknown Source)

at java.base/java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 4, 2020, 2:10pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/2 "2020-12-04T14:10:56Z")

</div>

I think this is a bug on our side. Not sure there’s anything you can do to fix it. I’ll make a ticket…

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [December 4, 2020, 2:41pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/3 "2020-12-04T14:41:30Z")

</div>

thanks, I stay tuned.

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [December 15, 2020, 8:55pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/4 "2020-12-15T20:55:40Z")

</div>

Did you find anything ?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 15, 2020, 9:00pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/5 "2020-12-15T21:00:01Z")

</div>

The ticket has been designated to be picked up “next sprint”. I don’t have any more details about it.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 12, 2021, 7:32pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/6 "2021-01-12T19:32:10Z")

</div>

This is fixed in 8.1.2.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [June 27, 2022, 2:19pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/7 "2022-06-27T14:19:17Z")

</div>

what if you can’t switch from 8.1.0?

any insight on how to make it either happen less often, or avoid it?  
I have a report using a historian query, and just that page is giving me the error of comparison method violates its general contract.  
@paul-griffith

broke on Sunday, had been working

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 27, 2022, 2:24pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/8 "2022-06-27T14:24:25Z")

</div>

> [@zacharyw.larson](#):
>
> what if you can’t switch from 8.1.0?

Then you can't get fixes. Upgrades contain bug fixes. No upgrade, no bug fix.

Sometimes there are work-arounds, sometimes not. As noted above, this is one of the unfortunate "nots".

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [June 27, 2022, 2:56pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/9 "2022-06-27T14:56:58Z")

</div>

I am going to avoid the simple table in reports for now, as it seems like the only thing that broke. (8.1.0)  
I don’t know if it uses the history manager in a similar manner.  
Other pages were not impacted. None of my pages use the getTagHistoryManager() function afaik.  
I think a reset of my gateway would temporarily fix the issue, but I don’t have the ability to do that yet.

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [June 27, 2022, 3:38pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/10 "2022-06-27T15:38:11Z")

</div>

> [@zacharyw.larson](#):
>
> what if you can't switch from 8.1.0?

Just for my silly curiosity 🙂 , but why can't you?

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [June 27, 2022, 3:49pm UTC](https://forum.inductiveautomation.com/t/taghistorymanager-queryhistory-java-lang-illegalargumentexception-comparison-method-violates-its-general-contract/41206/11 "2022-06-27T15:49:31Z")

</div>

I am too far down the totem pole of my company.  
Also, they had paid someone to make a bunch stuff in Ignition, and they don’t want to pay them to fix that stuff if it breaks upgrading probably.
