spreadsheet-cfml icon indicating copy to clipboard operation
spreadsheet-cfml copied to clipboard

NPE on newStreamingXlsx() or streamingXml = true

Open DiscountDarcy opened this issue 6 years ago • 13 comments
trafficstars

OpenJDK 8u181, Alpine Linux in Docker, Lucee 5.3.2.38-SNAPSHOT, lucee-spreadsheet 2.0.2.

Any call to newStreamingXlsx() or new() with streamingXml=true returns an NPE on this line in Spreadsheet.cfc:

arguments.workbook.createSheet( JavaCast( "String", arguments.sheetName ) );

Stack trace: `

java.lang.NullPointerException

Stacktrace | The Error Occurred in/app/modules/lucee-spreadsheet/Spreadsheet.cfc: line 647 645: arguments.sheetName = generateUniqueSheetName( arguments.workbook );646: if( !sheetExists( workbook=arguments.workbook, sheetName=arguments.sheetName ) ){647: arguments.workbook.createSheet( JavaCast( "String", arguments.sheetName ) );648: return;649: }called from /app/modules/lucee-spreadsheet/Spreadsheet.cfc: line 1100 called from /app/modules/lucee-spreadsheet/Spreadsheet.cfc: line 1114 called from /app/model/queryBuilder2/QueryBuilderDownloader.cfm: line 71 Java Stacktrace | lucee.runtime.exp.NativeException: java.lang.NullPointerException  at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)  at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)  at sun.awt.FontConfiguration.init(FontConfiguration.java:107)  at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)  at sun.font.SunFontManager$2.run(SunFontManager.java:431)  at java.security.AccessController.doPrivileged(Native Method)  at sun.font.SunFontManager.(SunFontManager.java:376)  at sun.awt.FcFontManager.(FcFontManager.java:35)  at sun.awt.X11FontManager.(X11FontManager.java:57)  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)  at java.lang.Class.newInstance(Class.java:442)  at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)  at java.security.AccessController.doPrivileged(Native Method)  at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)  at java.awt.Font.getFont2D(Font.java:491)  at java.awt.Font.canDisplayUpTo(Font.java:2060)  at java.awt.font.TextLayout.singleFont(TextLayout.java:470)  at java.awt.font.TextLayout.(TextLayout.java:531)  at org.apache.poi.ss.util.SheetUtil.getDefaultCharWidth(SheetUtil.java:273)  at org.apache.poi.xssf.streaming.AutoSizeColumnTracker.(AutoSizeColumnTracker.java:117)  at org.apache.poi.xssf.streaming.SXSSFSheet.(SXSSFSheet.java:82)  at org.apache.poi.xssf.streaming.SXSSFWorkbook.createAndRegisterSXSSFSheet(SXSSFWorkbook.java:664)  at org.apache.poi.xssf.streaming.SXSSFWorkbook.createSheet(SXSSFWorkbook.java:685)  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  at java.lang.reflect.Method.invoke(Method.java:498)  at lucee.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:56)  at lucee.runtime.reflection.Reflector.callMethod(Reflector.java:877)  at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:810)  at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1706)  at modules.lucee_spreadsheet270.spreadsheet_cfc$cf.udfCall3(/modules/lucee-spreadsheet/Spreadsheet.cfc:647)  at modules.lucee_spreadsheet270.spreadsheet_cfc$cf.udfCall(/modules/lucee-spreadsheet/Spreadsheet.cfc)  at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:106)  at lucee.runtime.type.UDFImpl._call(UDFImpl.java:342)  at lucee.runtime.type.UDFImpl.call(UDFImpl.java:215)  at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:766)  at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:767)  at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1706)  at modules.lucee_spreadsheet270.spreadsheet_cfc$cf.udfCall6(/modules/lucee-spreadsheet/Spreadsheet.cfc:1100)  at modules.lucee_spreadsheet270.spreadsheet_cfc$cf.udfCall(/modules/lucee-spreadsheet/Spreadsheet.cfc)  at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:106)  at lucee.runtime.type.UDFImpl._call(UDFImpl.java:342)  at lucee.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:205)  at lucee.runtime.type.scope.UndefinedImpl.callWithNamedValues(UndefinedImpl.java:779)  at lucee.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:845)  at lucee.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1725)  at modules.lucee_spreadsheet270.spreadsheet_cfc$cf.udfCall7(/modules/lucee-spreadsheet/Spreadsheet.cfc:1114)  at modules.lucee_spreadsheet270.spreadsheet_cfc$cf.udfCall(/modules/lucee-spreadsheet/Spreadsheet.cfc)  at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:106)  at lucee.runtime.type.UDFImpl._call(UDFImpl.java:342)  at lucee.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:205)  at lucee.runtime.ComponentImpl._call(ComponentImpl.java:678)  at lucee.runtime.ComponentImpl._call(ComponentImpl.java:565)  at lucee.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1946)  at lucee.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:845)  at lucee.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1725)  at model.querybuilder2.querybuilderdownloader_cfm$cf.call(/model/queryBuilder2/QueryBuilderDownloader.cfm:71)  at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:941)  at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:833)  at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:216)  at lucee.runtime.listener.ModernAppListener.onRequest(ModernAppListener.java:104)  at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2408)  at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2398)  at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2373)  at lucee.runtime.engine.Request.exe(Request.java:43)  at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1045)  at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:991)  at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97)  at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51)  at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)  at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)  at org.cfmlprojects.regexpathinfofilter.RegexPathInfoFilter.doFilter(RegexPathInfoFilter.java:47)  at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)  at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)  at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)  at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)  at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)  at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)  at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)  at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)  at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)  at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:64)  at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)  at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)  at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)  at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)  at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)  at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)  at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)  at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)  at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)  at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)  at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)  at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)  at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)  at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)  at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)  at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)  at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)  at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)  at io.undertow.server.Connectors.executeRootHandler(Connectors.java:336)  at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)  at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.NullPointerException

`

DiscountDarcy avatar Jan 18 '19 14:01 DiscountDarcy

Hi Samuel, I'm afraid I can't replicate this in my environment.

The test suite passes on Lucee 5.3.2.38-SNAPSHOT via CommandBox and it includes several calls to newStreamingXlsx(). I've tried some further custom tests and can't reproduce the NPE.

I'm using AdoptOpenJdk 1.8.0_202.

Could it be something to do with your Docker setup? I'm afraid I've no experience with that.

cfsimplicity avatar Jan 18 '19 16:01 cfsimplicity

Possibly. We are using the Ortus commandbox images which are using OpenJDK. Let me see if I can reproduce a basic Docker setup example later.

DiscountDarcy avatar Jan 18 '19 16:01 DiscountDarcy

I've created a skeleton app that just has this library and Coldbox (though I also tried instantiating it without Wirebox just to eliminate that as a culprit; no difference).

http://www.inleague.org/spreadsheet-npe.zip Just run docker-compose up and go to localhost:8080 (it'll take a few minutes to come up since it downloads the latest Lucee 5.3 snapshot). I added a couple lines testing addRows with autoSizeColumns but it doesn't even get that far.

DiscountDarcy avatar Jan 18 '19 20:01 DiscountDarcy

Sorry but as I say I'm not familiar with docker and don't have it set up. The tests all pass in a standard environment so it's most likely something to do with the docker set up, which I'm afraid I can't help with.

I've marked this ticket as "help wanted" in case there are others who can offer any insight.

cfsimplicity avatar Jan 18 '19 20:01 cfsimplicity

The distinction is unlikely to be Docker but perhaps the JRE. In this case it's OpenJDK 8u181.

You can forget Docker and just run it on any linux VM with that JRE. I packaged it in Docker because that's the least amount of work (there is no "Docker setup" ... that's the whole point; all the config is in the file in the zip)

DiscountDarcy avatar Jan 18 '19 20:01 DiscountDarcy

Could be the JRE but I'm using OpenJDK too and not seeing problems, albeit with a slightly later version. I was using Oracle 8u181 without issue too.

Sorry I'm not au fait with Linux either - Windows only I'm afraid.

cfsimplicity avatar Jan 18 '19 21:01 cfsimplicity

PS: By "docker set up" I meant the environment that it's creating, not the config itself. Should have been clearer.

cfsimplicity avatar Jan 18 '19 21:01 cfsimplicity

Hi Samuel, this sounds like it might be relevant to your issue:

https://dev.lucee.org/t/fixed-adoptopenjdk-and-fontconfig-error-ubuntu-18-04/5119

cfsimplicity avatar Feb 04 '19 19:02 cfsimplicity

Tried this again with fontconfig installed and also get the same NPE as with autoResizeColumns.

DiscountDarcy avatar Feb 17 '19 14:02 DiscountDarcy

@MordantWastrel Samuel, can I ask how you ended up dealing with this?

I'm slowly moving into the Docker world and have now come up against the issue with the latest commandbox:alpine image.

For me, adding RUN apk add fontconfig ttf-dejavu to my dockerfile and rebuilding fixes it.

cfsimplicity avatar Jul 25 '22 14:07 cfsimplicity

We didn't - we just didn't use the streaming XLSX stuff.

It's unlikely we're going to have the opportunity to dig into this in the near future, but the next time we're working on it we'll give that a shot! We also don't use alpine as much anymore in favor of ubuntu or debian-slim.

DiscountDarcy avatar Jul 25 '22 14:07 DiscountDarcy

OK, shame you've had to limit functionality.

I saw that Jon C addressed your ticket for the fontconfig to be added to the commandbox image, but my testing seems to show that isn't sufficient. A font also has to be installed (hence ttf-dejavu).

I've also noticed that the upstream adoptium JDK project has apparently taken this on board recently with their Alpine images, which will hopefully make this go away as an issue at some point. I tried refreshing my commandbox:alpine image but it doesn't seem to have filtered down yet.

I don't know if debian or ubuntu have the same issue, but presumably they could be fixed in the same way.

cfsimplicity avatar Jul 25 '22 16:07 cfsimplicity

I just tested the vanilla commandbox image, which seems to be based on Ubuntu, via eclipse-temurin:11-jre-focal, and it worked without any Dockerfile changes. That's presumably because the base image has fonts configured already.

cfsimplicity avatar Jul 26 '22 09:07 cfsimplicity