Bug 61960 - The log said "this error should NEVER happen Please raise a bug", So...
Summary: The log said "this error should NEVER happen Please raise a bug", So...
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-03 09:53 UTC by Simon
Modified: 2018-02-08 19:52 UTC (History)
0 users



Attachments
A export template in chinese (11.17 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2018-01-03 09:53 UTC, Simon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon 2018-01-03 09:53:19 UTC
Created attachment 35644 [details]
A export template in chinese

2018/01/03T17:46:39 [] [http-nio-8080-exec-7] ERROR c.v.i.a.c.a.AssetCategoryQueryController - Rule M2.4 exception : this error should NEVER happen! Please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach a file that triggers it, thanks!
org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Rule M2.4 exception : this error should NEVER happen! Please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach a file that triggers it, thanks!
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.getContentType(ContentTypeManager.java:343)
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.removeContentType(ContentTypeManager.java:256)
	at org.apache.poi.openxml4j.opc.OPCPackage.removePart(OPCPackage.java:958)
	at org.apache.poi.openxml4j.opc.PackagePart.getOutputStream(PackagePart.java:522)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.commit(XSSFWorkbook.java:1687)
	at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:464)
	at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:211)
	at com.valuedaas.info.asset.controller.assetquery.AssetCategoryQueryController.export(AssetCategoryQueryController.java:314)
	at com.valuedaas.info.asset.controller.assetquery.AssetCategoryQueryController$$FastClassBySpringCGLIB$$80e5b13d.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
	at com.valuedaas.info.asset.controller.assetquery.AssetCategoryQueryController$$EnhancerBySpringCGLIB$$4dd9610d.export(<generated>)
	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 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.valuedaas.info.asset.common.filter.UserAuthFilter.doFilter(UserAuthFilter.java:90)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:167)
	at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:80)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)




code:


// 循环查询结果
		FileInputStream fis = null;
		InputStream is = null;
		Workbook wb = null;
		MongoCursor<Document> cursor = null;
		try {
			
			
			is = new FileInputStream(new File("C:\\Users\\chenhua\\git\\information-backend\\target\\政务信息资源目录-模板.xlsx"));
			
//			is = new FileInputStream(new File(Class.class.getClass().getResource("/").getPath() + "/政务信息资源目录-模板.xlsx") );
			wb = new XSSFWorkbook(is);
			Sheet sheet = wb.getSheetAt(0); // 只处理第一个sheet
			int rowNum = 2;
			// 普通单元格
			XSSFCellStyle normallCellStyle = (XSSFCellStyle) wb.createCellStyle();
			normallCellStyle.setAlignment(CellStyle.VERTICAL_CENTER);
			// style.setWrapText(true);
			normallCellStyle.setBorderBottom(CellStyle.BORDER_THIN);
			normallCellStyle.setBorderLeft(CellStyle.BORDER_THIN);
			normallCellStyle.setBorderRight(CellStyle.BORDER_THIN);
			normallCellStyle.setBorderTop(CellStyle.BORDER_THIN);
			normallCellStyle.setDataFormat(wb.createDataFormat().getFormat("#,##0"));// 这样写百分百变成货币

			cursor = deptInfoAssetMgmtService.mongoCollection().aggregate(pipeline).batchSize(200).iterator();
			while (cursor.hasNext()) {
				rowNum++;
				Document d = cursor.next();
				Row row = sheet.getRow(rowNum);
				row.getCell(infoAssetSn).setCellValue(rowNum - 2);
				String categoryKey = d.getString(DeptInfoAsset.CATEGORY);
				String categoryName = categoryMap.get(categoryKey);
				row.getCell(infoAssetCategoryIndex).setCellValue(categoryName);
				// String subjectKey = d.getString(DeptInfoAsset.SUBJECT);
				// String subjectName = "";
				// if (categoryKey.equals("1")) { // 根据一级分类不同,采用不同的 二级分类字典
				// subjectName = jichuSubCategory.getOrDefault(subjectKey, "");
				// } else if (categoryKey.equals("2")) {
				// subjectName = zhutiSubCategory.getOrDefault(subjectKey, "");
				// } else if (categoryKey.equals("3")) {
				// subjectName = bumenSubCategory.getOrDefault(subjectKey, "");
				// }
				// row.getCell(infoAssetSubjectIndex).setCellValue(subjectName);
				row.getCell(infoAssetNameIndex).setCellStyle(normallCellStyle);
				row.getCell(infoAssetNameIndex).setCellValue(d.getString(DeptInfoAsset.NAME));
				row.getCell(infoAssetNoIndex).setCellStyle(normallCellStyle);
				row.getCell(infoAssetNoIndex).setCellValue(d.getString(DeptInfoAsset.NO));

				wb.write(new FileOutputStream(new File(exportFilePath)));
				wb.close();
			}


error occur at this line: wb.write(new FileOutputStream(new File(exportFilePath)));
Comment 1 Simon 2018-01-03 09:56:42 UTC
version is  3.14  , spring boot si  1.5.7.RELEASE
Comment 2 Simon 2018-01-03 09:57:55 UTC
version is  3.14  , spring boot si  1.5.7.RELEASE
Comment 3 Alain Fagot Bearez 2018-01-06 03:28:14 UTC
It seems that your code is closing your workbook inside the while loop. Being so, on second attempt to get a row from your sheet, the exception is raised since no reading is allowed from a closed document.

I recommend three actions:
  1. update your dependencies to POI 3.17;
  2. move the two last lines of the while loop outside of the loop;
  3. report about your progress on this ticket.
Comment 4 Dominik Stadler 2018-02-08 19:52:32 UTC
This seems to be a code-error on the user-side by closing the document too early, thus closing this for now here.