cfsimplicity / spreadsheet-cfml

Standalone library for working with spreadsheets and CSV in CFML
MIT License
129 stars 36 forks source link

java.util.TreeMap$ValueIterator Error after moving to Lucee 6 #379

Open kabutotx opened 1 month ago

kabutotx commented 1 month ago

Moved from Lucee 5, Spreadsheet 4.1.1 to Lucee 6.1.0.243, Java 11.0.24, and Spreadsheet 4.2.1.

My code does a writeFileFromQuery().

Get: "ERROR","http-nio-8888-exec-9","10/07/2024","12:19:34","dynamic","failed to access class java.util.TreeMap$ValueIterator from class lucee.invoc.wrap.v2.java.util.TreeMap$ValueIterator.next_11mw6cpi3sk2k (java.util.TreeMap$ValueIterator is in module java.base of loader 'bootstrap'; lucee.invoc.wrap.v2.java.util.TreeMap$ValueIterator.next_11mw6cpi3sk2k is in unnamed module of loader lucee.transformer.dynamic.DynamicClassLoader @64f35d5d);java.lang.IllegalAccessError: failed to access class java.util.TreeMap$ValueIterator from class lucee.invoc.wrap.v2.java.util.TreeMap$ValueIterator.next_11mw6cpi3sk2k (java.util.TreeMap$ValueIterator is in module java.base of loader 'bootstrap'; lucee.invoc.wrap.v2.java.util.TreeMap$ValueIterator.next_11mw6cpi3sk2k is in unnamed module of loader lucee.transformer.dynamic.DynamicClassLoader @64f35d5d) at lucee.invoc.wrap.v2.java.util.TreeMap$ValueIterator.next_11mw6cpi3sk2k.apply(Unknown Source) at lucee.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:64) at lucee.runtime.reflection.Reflector.callMethod(Reflector.java:928) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:840) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at spreadsheet_cfc$cf.udfCall5(/Spreadsheet.cfc:781) at spreadsheet_cfc$cf.udfCall(/Spreadsheet.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:224) at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:782) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:796) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1996) at spreadsheet_cfc$cf.udfCalld(/Spreadsheet.cfc:1713) at spreadsheet_cfc$cf.udfCall(/Spreadsheet.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:112) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:357) at lucee.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:214) at lucee.runtime.type.scope.UndefinedImpl.callWithNamedValues(UndefinedImpl.java:800) at lucee.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:875) at lucee.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:2028) at spreadsheet_cfc$cf.udfCalld(/Spreadsheet.cfc:1779) at spreadsheet_cfc$cf.udfCall(/Spreadsheet.cfc) ....

kabutotx commented 1 month ago

I just noticed changing back to writing xls instead of xlsx works fine.

cfsimplicity commented 1 month ago

My code does a writeFileFromQuery().

Is your code really as simple as that? If not, can you elaborate a little more so I can try and replicate it. Thanks.

kabutotx commented 1 month ago

Pretty much. I just query from a DB and add one column to query.

<cfscript>
spreadsheet = New spreadsheet();
filepath = ExpandPath( "file.xlsx" );
spreadsheet.writeFileFromQuery( query,filepath,true );
</cfscript>
<a href=file.xlsx>Data file (xlsx)</a>
cfsimplicity commented 1 month ago

Thanks, l'm getting the same error with this:

spreadsheet = new spreadsheet.Spreadsheet()
query = QueryNew( "Header1,Header2", "VarChar,VarChar", [ [ "a","b" ], [ "c","d" ] ] )
filepath = ExpandPath( "test.xlsx" )
spreadsheet.writeFileFromQuery( query, filepath, true )

In fact, I currently cannot get the test suite to run on Lucee 6.1.0.243. It keeps timing out.

Downgrading to the previous 6.0.3.1 release it all works fine though. So clearly an issue with the latest Lucee release.

Strange though, as my understanding was that the Lucee team were using this library to smoke test.

kabutotx commented 1 month ago

I found the below works.

<cfscript>
    spreadsheet = New spreadsheet();
    workbook = spreadsheet.new();
    spreadsheet.addRows( workbook, query );
    filepath = ExpandPath( "file.xlsx" );
    spreadsheet.write( workbook, filepath, true );
</cfscript>
kabutotx commented 1 month ago

This also works adding xml format

<cfscript>
    spreadsheet = New spreadsheet();
    spreadsheet.setDefaultWorkbookFormat( "xml" );
    workbook = spreadsheet.new();
    spreadsheet.addRows( workbook, query );
    filepath = ExpandPath( "file.xlsx" );
    spreadsheet.write( workbook, filepath, true );
</cfscript>
cfsimplicity commented 1 month ago

workbook = spreadsheet.newXlsx() works as well. The issue is with writeFileFromQuery() rather than addRows()/write().

cfsimplicity commented 1 month ago

The issue seems to be with a call to formatRow() which by default makes the first row bold. Setting that to false avoids the error:

spreadsheet.writeFileFromQuery( data=query, filepath=filepath, overwrite=true, boldHeaderRow=false )

Calling formatRow() on its own with an XLSX is enough to trigger the exception:

spreadsheet = new spreadsheet.Spreadsheet()
workbook = spreadsheet.newXlsx()
spreadsheet.addRow( workbook, [ "test" ] )
spreadsheet.formatRow( workbook, { bold: true }, 1 )

As I say, this seems to be a problem with the current release of Lucee: version 6.1.0.243. I upgraded to the next minor version- i.e. 6.1.1.0-SNAPSHOT - and the error went away. I looked in Lucee's Jira but there didn't seem to be any tickets fixed in that version so I'm not sure what the cause is/was.