Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save trycf/730bda23df47a7d62e5e8b9cf447e858 to your computer and use it in GitHub Desktop.

Select an option

Save trycf/730bda23df47a7d62e5e8b9cf447e858 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
/**
* BoxLang StructSort Comparison Contract Violation - Reproduction Case
*
* This reproduces the error:
* "Comparison method violates its general contract! java.lang.IllegalArgumentException"
*
* Issue occurs when sorting a struct with nested structs containing timestamp fields
* while simulating concurrent access patterns (like ColdBox cache operations).
*/
// Simulate ConcurrentStore pool structure
pool = {};
// Populate with cache entries (mimics CacheBoxProvider.set operations)
for ( i = 1; i <= 5000; i++ ) {
pool[ "cache_key_#i#" ] = {
object: "cached_value_#i#",
hits: randRange( 0, 1000 ),
timeout: "", // Empty string like in real cache
lastAccessTimeout: "", // Empty string like in real cache
created: now() - randRange( 0, 100 ),
lastAccessed: now() - randRange( 0, 100 ), // Very close timestamps
isExpired: false
};
}
writeDump( server.boxlang.buildDate );
// Simulate rapid concurrent access + sort (like LRU policy eviction)
for ( attempt = 1; attempt <= 50; attempt++ ) {
try {
for ( j = 1; j <= 100; j++ ) {
randomKey = "cache_key_#randRange( 1, 5000 )#";
if ( structKeyExists( pool, randomKey ) ) {
pool[ randomKey ].hits++;
pool[ randomKey ].lastAccessed = now();
}
}
// This is where the error occurs - sorting during concurrent access
sorted = structSort(
pool,
"numeric",
"asc",
"lastAccessed"
);
writeOutput( "Attempt #attempt#: OK (#arrayLen( sorted )# keys)<br>" );
} catch ( any e ) {
writeOutput( "<strong>Attempt #attempt#: ERROR</strong><br>" );
writeOutput( "Message: #e.message#<br>" );
writeOutput( "Type: #e.type#<br>" );
writeDump( var = e, label = "Full Error" );
break;
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment