ObjectSave causes java.io.UTFDataFormatException - java-io

Raised as bug with Railo https://issues.jboss.org/browse/RAILO-2698 - this question should be closed
I am currently attempting to ObjectSave() on a rather complex Struct which contains instances of some CFCs among other data using the following cfscript (this is a test script I put together to reproduce the issue)
<cfscript>
thisState = session.objBasket.getState();
writedump(thisState); // dumps the object successfully
ObjectSave(thisState); // causes java.io.UTFDataFormatException
</cfscript>
I am getting the following error java.io.UTFDataFormatException (stack trace follows). Does anyone know of a way to fix this, or is it a matter of simply trying to use the wrong tool for the job?
Railo versions the error occurs on
Railo 4.1.1.009 final (Java 1.7.0_45)
Railo 4.1.1.009 final (Java 1.7.0_17)
Railo 4.1.2.001 final (Java 1.7.0_45) (Preview release)
Railo versions the error does not occur on
Railo 4.0.4.001 final (Java 1.7.0_45)
Stack trace of the error
java.io.UTFDataFormatException at
java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:2163):2163
at
java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:2006):2006
at
java.io.ObjectOutputStream.writeUTF(ObjectOutputStream.java:868):868
at
railo.runtime.ComponentImpl.writeExternal(ComponentImpl.java:1975):1975
at
java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1458):1458
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429):1429
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177):1177
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347):347
at java.util.HashMap.writeObject(HashMap.java:1133):1133 at
sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source):-1 at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43):43
at java.lang.reflect.Method.invoke(Method.java:606):606 at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988):988
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495):1495
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431):1431
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177):1177
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347):347
at
railo.commons.collection.AbstractMapPro.writeExternal(AbstractMapPro.java:49):49
at
java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1458):1458
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429):1429
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177):1177
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547):1547
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508):1508
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431):1431
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177):1177
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347):347
at java.util.HashMap.writeObject(HashMap.java:1133):1133 at
sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source):-1 at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43):43
at java.lang.reflect.Method.invoke(Method.java:606):606 at
java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988):988
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1495):1495
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431):1431
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177):1177
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347):347
at
railo.commons.collection.AbstractMapPro.writeExternal(AbstractMapPro.java:49):49
at
java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1458):1458
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1429):1429
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177):1177
at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1547):1547
at
java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1508):1508
at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1431):1431
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1177):1177
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347):347
at
railo.runtime.converter.JavaConverter.serialize(JavaConverter.java:67):67
at
railo.runtime.functions.other.ObjectSave.call(ObjectSave.java:31):31
at
railo.runtime.functions.other.ObjectSave.call(ObjectSave.java:22):22
at
mso.clientobject_cfc$cf._3(/var/www/html/www/www.simon.test/mso/ClientObject.cfc:476):476
at
mso.clientobject_cfc$cf.udfCall(/var/www/html/www/www.simon.test/mso/ClientObject.cfc):-1
at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:94):94 at
railo.runtime.type.UDFImpl._call(UDFImpl.java:307):307 at
railo.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:198):198
at
railo.runtime.type.scope.UndefinedImpl.callWithNamedValues(UndefinedImpl.java:709):709
at
railo.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:738):738
at
railo.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1513):1513
at
mso.clientobject_cfc$cf._3(/var/www/html/www/www.simon.test/mso/ClientObject.cfc:437):437
at
mso.clientobject_cfc$cf.udfCall(/var/www/html/www/www.simon.test/mso/ClientObject.cfc):-1
at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:94):94 at
railo.runtime.type.UDFImpl._call(UDFImpl.java:307):307 at
railo.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:198):198
at railo.runtime.ComponentImpl._call(ComponentImpl.java:617):617 at
railo.runtime.ComponentImpl._call(ComponentImpl.java:499):499 at
railo.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1732):1732
at
railo.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:738):738
at
railo.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1513):1513
at
mso.proxyclientobject_cfm$cf._1(/var/www/html/www/www.simon.test/mso/proxyClientObject.cfm:19):19
at
mso.proxyclientobject_cfm$cf.udfCall(/var/www/html/www/www.simon.test/mso/proxyClientObject.cfm):-1
at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:94):94 at
railo.runtime.type.UDFImpl._call(UDFImpl.java:307):307 at
railo.runtime.type.UDFImpl.call(UDFImpl.java:211):211 at
railo.runtime.ComponentImpl._call(ComponentImpl.java:616):616 at
railo.runtime.ComponentImpl._call(ComponentImpl.java:499):499 at
railo.runtime.ComponentImpl.call(ComponentImpl.java:1715):1715 at
railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:712):712
at
railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1503):1503
at
preparecosting_cfm$cf.call(/var/www/html/www/www.simon.test/prepareCosting.cfm:24):24
at
railo.runtime.PageContextImpl.doInclude(PageContextImpl.java:834):834
at
railo.runtime.PageContextImpl.doInclude(PageContextImpl.java:781):781
at
application_cfc$cf._1(/var/www/html/www/www.simon.test/Application.cfc:177):177
at
application_cfc$cf.udfCall(/var/www/html/www/www.simon.test/Application.cfc):-1
at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:94):94 at
railo.runtime.type.UDFImpl._call(UDFImpl.java:307):307 at
railo.runtime.type.UDFImpl.call(UDFImpl.java:211):211 at
railo.runtime.ComponentImpl._call(ComponentImpl.java:616):616 at
railo.runtime.ComponentImpl._call(ComponentImpl.java:499):499 at
railo.runtime.ComponentImpl.call(ComponentImpl.java:1715):1715 at
railo.runtime.listener.ModernAppListener.call(ModernAppListener.java:388):388
at
railo.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:204):204
at
railo.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:18):18
at
railo.runtime.PageContextImpl.execute(PageContextImpl.java:2167):2167
at
railo.runtime.PageContextImpl.execute(PageContextImpl.java:2134):2134
at
railo.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:335):335
at railo.loader.servlet.CFMLServlet.service(CFMLServlet.java:29):29 at
javax.servlet.http.HttpServlet.service(HttpServlet.java:728):728 at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305):305
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210):210
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222):222
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123):123
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472):472
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171):171
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99):99
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118):118
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407):407
at
org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200):200
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589):589
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310):310
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145):1145
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615):615
at java.lang.Thread.run(Thread.java:744):744
Unit test + accompanying cfc that can be used to reproduce
javaErrorTest.cfc (Unit test)
component extends='mxunit.framework.TestCase' {
public void function trySavingLargeNestedStruct() {
// Prove that it doesn't happen with nested structures
var nestedStruct = {};
var nestInMe = nestedStruct;
// Make a big struct
var nestedStruct = {};
var v = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
for (var i in v) {
for (var j in v) {
for (var k in v) {
for (var l in v) {
nestedStruct[i][j][k][l] = {};
}
}
}
}
debug('Nested struct len = '&len(serialize(nestedStruct)));
ObjectSave(nestedStruct);
debug('Nested struct saved without error');
}
public void function triggerUTFDataFormatException() {
// Prove that it happens with objects nested deeply
var previousLength = 0;
for (var i=600;i<700;i++) {
objTest = new TestObject( levels = i );
var strSerialized = serialize(objTest);
try {
ObjectSave(objTest);
} catch (java.io.UTFDataFormatException e) {
// Expected place of java.io.UTFDataFormatException
debug('Levels = '&i-1&' has serialize() length = '&previousLength);
debug('Levels = '&i&' has serialize() length = '&Len(strSerialized));
debug(strSerialized);
debug(e);
fail('java.io.UTFDataFormatException (expected) error thrown');
} catch (any e) {
debug(e);
fail('Error thrown, not not the expected one');
}
previousLength = Len(strSerialized);
}
}
}
TestObject.cfc (Used within the failing test)
component {
public TestObject function init(
required numeric levels = 0
) {
variables.a = (arguments.levels > 0)?new TestObject( levels = arguments.levels - 1 ):{};
return this;
}
}

Look at the stack trace. It answers all your questions.
java.io.UTFDataFormatException at java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:2163):2163 at java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:2006):2006
A glance at the Javadoc shows that this exception is thrown by writeUTF() if the data to be written is longer than 65535 bytes.
railo.runtime.ComponentImpl.writeExternal(ComponentImpl.java:1975):1975
This is the code that calls writeUTF(). So it appears to be a bug in the railo.runtime.ComponentImpl class. It shouldn't be calling writeUTF() for such a long string.

The following 2 methods are what I am using in place of ObjectSave and ObjectLoad until the Railo bug is corrected. It seems to function up to a decent level of complexity.
// Replaces ObjectSave
private binary function serializeState(
required struct inState
) {
var strSerialized = serialize(arguments.inState);
return strSerialized.GetBytes();
}
// Replaces ObjectLoad
private struct function deserializeState(
required binary inState
) {
var strSerialized = ToString(arguments.inState);
var stcDeserialized = evaluate(strSerialized);
return stcDeserialized;
}

Related

UWP: calculate expected size of screenshot using multiple monitor setup

Right, parsing the clipboard, I am trying to detect if a stored bitmap in there might be the result of a screenshot the user took.
Everything is working fine as long as the user only has one monitor. Things become a bit more involved with two or more.
I am using the routing below to grab all the displays in use. Now, since I have no idea how they are configured to hang together, I do not know how to calculate the size of the screenshot (that Windows would produce) from that information.
I explicitly do not want to take a screenshot myself to compare. It's a privacy promise by my app.
Any ideas?
Here is the code for the size extractor, run in the UI thread.
public static async Task<Windows.Graphics.SizeInt32[]> GetMonitorSizesAsync()
{
Windows.Graphics.SizeInt32[] result = null;
var selector = DisplayMonitor.GetDeviceSelector();
var devices = await DeviceInformation.FindAllAsync(selector);
if (devices?.Count > 0)
{
result = new Windows.Graphics.SizeInt32[devices.Count];
int i = 0;
foreach (var device in devices)
{
var monitor = await DisplayMonitor.FromInterfaceIdAsync(device.Id);
result[i++] = monitor.NativeResolutionInRawPixels;
}
}
return result;
}
Base on Raymonds comment, here is my current solution in release code...
IN_UI_THREAD is a convenience property to see if the code executes in the UI thread,
public static Windows.Foundation.Size GetDesktopSize()
{
Int32 desktopWidth = 0;
Int32 desktopHeight = 0;
if (IN_UI_THREAD)
{
var regions = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView()?.WindowingEnvironment?.GetDisplayRegions()?.Where(r => r.IsVisible);
if (regions?.Count() > 0)
{
// Get grab the most left and the most right point.
var MostLeft = regions.Min(r => r.WorkAreaOffset.X);
var MostTop = regions.Min(r => r.WorkAreaOffset.Y);
// The width is the distance between the most left and the most right point
desktopWidth = (int)regions.Max(r => r.WorkAreaOffset.X + r.WorkAreaSize.Width - MostLeft);
// Same for height
desktopHeight = (int)regions.Max(r => r.WorkAreaOffset.Y + r.WorkAreaSize.Height - MostTop);
}
}
return new Windows.Foundation.Size(desktopWidth, desktopHeight);
}

Crashes after parsing the equation

The application want to parse a string equation to mathematics and return the data to user. for this purpose the library is used is exprtk
for easy analysis I have shared minimum working code
minimum working code
when application parses the string to code back to back [multithreaded but locked]
void reset()
{
// Why? because msvc doesn't support swap properly.
//stack_ = std::stack<std::pair<char,std::size_t> >();
/**
it was crashing on destructor on ~deque()
stating memory reallocation
so I change it to pop so for now this has been resolved
*/
while(stack_.size()) stack_.pop();
state_ = true;
error_token_.clear();
}
now the code always crashes on
static inline void destroy(control_block*& cntrl_blck)
{
if (cntrl_blck)
{
/**now crashes on this condition check*/
if ( (0 != cntrl_blck->ref_count) && (0 == --cntrl_blck->ref_count) )
{
delete cntrl_blck;
}
cntrl_blck = 0;
}
}
UPDATE
pastebin code updated new code with main has been added with main and minimum working code.
all the shared_ptr has been removed. now they are normal objects.
as for exprtk reset function has been changed to original one
void reset()
{
// Why? because msvc doesn't support swap properly.
stack_ = std::stack<std::pair<char,std::size_t> >();
state_ = true;
error_token_.clear();
}
and backtrace of gdb has been added backtrace

node.js Number.prototype isn't behaving as expected

I'm trying to do a little math library to facilitate my app, this however is throwing an off error.
TypeError: Object 25 has no method 'permutation'
function permutate(p) {
var states = new Number(p.length)
chat( states.permutation(states) )
}
Number.prototype.factorial = function() {
for(var i = 2; i <= this; i++)
n*=i
return n
}
Number.prototype.permutation = function(r) {
return (this.factorial() / (this-r).factorial())
}
in addition to hopefully fixing my code, I'm really curious why the objects type is being interpreted as a number primitive? (or whatever is really going on here)

Haxe - sending enum as flags to a function

I'm just trying to convert my code from C# to Haxe NME. I use enums as flags.
[Flags]
enum State
{
StateOne = 1,
StateTwo = 2,
StateThree = 4
}
And use it
if (someObj.HasState(State.StateOne | State.StateTwo))
{
// Contains both the states. Do something now.
}
I had no idea on how to do this in Haxe NME.
Thanks.
In Haxe 3, there is haxe.EnumFlags. This uses Haxe 3 Abstract Types which basically wrap an underlying type, in this case, it uses an Int, just like you have done - but then it wraps it up in a pretty API so you don't have to worry about the details.
Here is some sample code:
import haxe.EnumFlags;
class EnumFlagTest
{
static function main()
{
var flags = new EnumFlags<State>();
flags.set(StateOne);
flags.set(StateTwo);
flags.set(StateThree);
flags.unset(StateTwo);
if (flags.has(StateOne)) trace ("State One active");
if (flags.has(StateTwo)) trace ("State Two active");
if (flags.has(StateThree)) trace ("State Three active");
if (flags.has(StateOne) && flags.has(StateTwo)) trace ("One and Two both active");
if (flags.has(StateOne) && flags.has(StateThree)) trace ("One and Three both active");
}
}
enum State
{
StateOne;
StateTwo;
StateThree;
}
All of this works is stored as a standard Int, and uses integer operators like you have done, so it should be pretty fast (no wrapping in an external object). If you want to see how it works under the box, the source code for EnumFlags can be viewed here.
If you're still on Haxe 2, then you could create an object that is really similar, but of course, it has to create an object as well as the integer, so if you're doing thousands (millions?) of them then you might get a slow down. The equivalent code, that should work with Haxe 2 (though I haven't checked):
class MyEnumFlags<T:EnumValue>
{
var i:Int;
public function new(?i=0)
{
this.i = i;
}
public inline function has( v : T ) : Bool {
return i & (1 << Type.enumIndex(v)) != 0;
}
public inline function set( v : T ) : Void {
i |= 1 << Type.enumIndex(v);
}
public inline function unset( v : T ) : Void {
i &= 0xFFFFFFF - (1 << Type.enumIndex(v));
}
public inline static function ofInt<T:EnumValue>( i : Int ) : MyEnumFlags<T> {
return new MyEnumFlags<T>(i);
}
public inline function toInt() : Int {
return i;
}
}
I've managed to find it. I had trouble using enums but I had been successful using constants. This is the simple test file I used.
package ;
class FlagsTest
{
static inline var FLG_1:Int = 1;
static inline var FLG_2:Int = 2;
public static function main() : Void
{
var flag:Int = FLG_1;
if (hasFlag(flag, FLG_1))
{
trace ("Test 1 passed");
}
flag |= FLG_2;
if (hasFlag(flag, FLG_2))
{
trace ("Test 2 passed");
}
}
public static function hasFlag( flags:Int, flag:Int ) : Bool
{
return ((flags & flag) == flag) ? true : false;
}
}
Output:
FlagsTest.hx line 14: Test 1 passed
FlagsTest.hx line 19: Test 2 passed

Comparison method violates its general contract! Java 7 only

I know this has been an issue for a while now, and checked all previously answers I could get, but still this one doesn't work.
The object 'crew' represents crewmembers with ranks and other items. The comparison should be made by comparing 'assigned_rank', an int value, and if this value is equal in both instances, then 'is_trainer', a boolean, should make the difference.
This method worked great as long as it was running with java < 7. But since Java 7 I keep getting this one:
java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeLo(ComparableTimSort.java:714)
at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:451)
at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:376)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:182)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:146)
at java.util.Arrays.sort(Arrays.java:472)
at java.util.Collections.sort(Collections.java:155)
at dormas_flightlog.Query.getCrew(Query.java:714)
Here is the source, where some potentially dangerous parts have allready been out-commented, but it still does not work:
public class crew implements Serializable, Comparable<crew> {
private static final long serialVersionUID = 36L;
private int flightID = 0;
private int assigned_rank = 25;
private boolean is_trainer = false;
...
#Override
public int compareTo(crew him) {
int myRank = this.getAssigned_rank();
int hisRank = him.assigned_rank;
if (this == him) {
return 0;
}
if (myRank > hisRank) {
return 1;
}
if (myRank < hisRank) {
return -1;
}
if (myRank == hisRank) {
// if (is_trainer && !o.is_trainer) {
// i = 1;
// }
// if (!is_trainer && o.is_trainer) {
// i = -1;
// }
// if (is_trainer && o.is_trainer) {
// i = 0;
// }
// if (!is_trainer && !o.is_trainer) {
// i = 0;
// }
return 0;
}
return 0;
}
#Override
public int hashCode() {
int hash = 7;
hash = 31 * hash + this.assigned_rank;
hash = 31 * hash + (this.is_trainer ? 1 : 0);
return hash;
}
#Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
int myRank = this.getAssigned_rank();
int hisRank = 0;
if (o instanceof crew) {
crew him = (crew) o;
hisRank = him.assigned_rank;
} else {
return false;
}
if (myRank > hisRank) {
return false;
}
if (myRank < hisRank) {
return false;
}
if (myRank == hisRank) {
// if (is_trainer && !o.is_trainer) {
// i = 1;
// }
// if (!is_trainer && o.is_trainer) {
// i = -1;
// }
// if (is_trainer && o.is_trainer) {
// i = 0;
// }
// if (!is_trainer && !o.is_trainer) {
// i = 0;
// }
return true;
}
return false;
}
}
Implementing equals() was just a try to solve this problem. The given exception comes with or without equals(). I cannot see how the compareTo-method violates its contract. Any help is greatly appreciated....one day this code has to work with java 7 and I don't know how...
Thanks
see this:
From http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#source
Area: API: Utilities Synopsis: Updated sort behavior for Arrays and
Collections may throw an IllegalArgumentException
Description: The sorting algorithm used by java.util.Arrays.sort and
(indirectly) by java.util.Collections.sort has been replaced. The new
sort implementation may throw an IllegalArgumentException if it detects
a Comparable that violates the Comparable contract. The previous
implementation silently ignored such a situation. If the previous
behavior is desired, you can use the new system
property java.util.Arrays.useLegacyMergeSort, to restore previous
mergesort behavior.
Nature of Incompatibility: behavioral
RFE: 6804124
For more detailed info, see the bug database reference here.
maybe you just have NaN values which you compare through Collections.sort(...), this has been a problem to me and I got that exception even having right implementation of compare(obj1, obj2) method! Check that!
I was able to solve this error cause it was a bug in jdk7.
here I found the solution:
"Comparison method violates its general contract!" - TimSort and GridLayout
Basically i just had to add the
JAVA_OPTS="$JAVA_OPTS -Djava.util.Arrays.useLegacyMergeSort=true"
to my jboss
Unfortunately, none of the solutions work for Android. TimSort is used deep in Android's ViewGroup relating to addChildrenForAccessibility that shows up under Java 7 & 8. No user code is involved in any comparison.
From other reports, it is related to having RelativeLayout with overlapping items as is commonly done. For example, a TextView that appears over an Image, or two items at the same location, where you only set one visible at a time.
https://code.google.com/p/android/issues/detail?id=55933
I've not found any way around the bug. You can't set a -Djava option in Android Studio or Eclipse (at least that I could find). Forcing use of Java 1.6 should work, but doesn't. Seems like Amazon's newer Fire tablets and phones are far more sensitive to this bug than other devices.
There are rumors Java 9 will have a fix such as a run-time option that works, but with a bug that's been around for years, I have doubts it will ever be fixed - especially considering the animosity between Oracle and Google. Any yes, perhaps the bug is really deep in the Android code and should be fixed there. With more than a billion devices out there, that's not a viable solution for all the existing devices.

Resources