Exception when using Apache POi with OOXML java.lang.NoSuchFieldError: Factory - apache-poi

I upgraded to Apache PO 5.2.3 recently (using JDK 1.8) and I have the following exception when creating a new Workbook:
Exception in thread "main" java.lang.NoSuchFieldError: Factory
at org.apache.poi.xssf.model.ThemesTable.readFrom(ThemesTable.java:119)
at org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:87)
at org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:61)
at org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:661)
at org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:165)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:260)
at org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(XSSFWorkbookFactory.java:118)
at org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.create(XSSFWorkbookFactory.java:98)
at org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.create(XSSFWorkbookFactory.java:36)
at org.apache.poi.ss.usermodel.WorkbookFactory.lambda$create$2(WorkbookFactory.java:224)
at org.apache.poi.ss.usermodel.WorkbookFactory.wp(WorkbookFactory.java:329)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:224)
at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:185)
I have the following dependencies, and looking at this StackOverflow question: Exception in thread "main" java.lang.NoSuchFieldError: Factory, I thought I had the correct dependencies. My dependencies are:
The test code I am using is very simple:
File file = new File("L://WRK/Java/designchecker/common/configfiles/Styleset.xlsx");
try {
Workbook workbook = WorkbookFactory.create(new FileInputStream(file));
} catch (Exception ex) {
ex.printStackTrace();
}
I am sure that some of my version are incorrect, but I don't know which. Can somebody point to me where is my library version mismatch?

As PJ. Fanning wrote, I need to remove these two libraries:
ooxml-schemas 1.4.jar
poi-ooxml-schemas-4.1.2.jar
When I do this, the exception disappear.

Related

C# | Catch exception from a dynamically loaded dll

I'm trying to write a C# (WPF - not that it matters in that context) application that loads a DLL dynamically using this code:
private Assembly GetAssembly(string assemblyPath)
{
AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
return AppDomain.CurrentDomain.Load(assemblyName);
}
Loading the dll works fine and also using it works.
The problem is - when I try catching an exception when calling a function on that dynamically loaded DLL it is not caught in my application
Note: The dynamically loaded dll was also written by me so I know for a fact that an exception occurs
The try/catch section looks like that
try
{
result = aseInstance.Compile();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
I also tried using the following code:
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
but didn't help..
One more thing that might be worth mentioning - useInstance is a dynamic
I don't want my code to have to "know" which class it is loading so I'm using dynamic
If i do the same using references everything works and the exception is caught
I'd love some help here!
Thanks

karate: Picking up feature files from absolute class path

I am following the DemoTestSelected.java sample to run the feature file in my Karate Framework. It's working fine when i run them in intellij. But when i convert it into jar and then run from it, it is throwing the below error.
java.lang.RuntimeException: java.io.FileNotFoundException: file:\C:\Src_path\target\app-jar-with-dependencies.jar!\features\app\app_1.0.4_a.feature (The filename, directory name, or volume label syntax is incorrect)
I explored the Karate Core code and found the below class which might be problem.
public static URL toFileUrl(String path) {
path = StringUtils.trimToEmpty(path);
File file = new File(path);
try {
return file.getAbsoluteFile().toURI().toURL();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
I am stuck here, any help would be appreciated.
First - no one has ever reported this problem and teams normally don't need to bundle tests into a JAR.
Second - if you use the classpath: prefix, you should be able to load feature files from within even JAR files. So please use it and it is documented here: https://github.com/intuit/karate#reading-files
* def result = call read('classpath:some-reusable-steps.feature')
If this does not solve the problem, please follow the instructions here and submit an issue: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue - please explain what you are trying to do differently also.

How can I figure out which version of apache POI is needed for jXLS 2.3.0?

This is my Gradle file:
compile 'org.apache.poi:poi:3.13'
compile 'org.jxls:jxls-jexcel:1.0.6'
compile 'org.jxls:jxls-poi:1.0.9'
compile 'org.jxls:jxls:2.3.0'
It looks like I'm using the wrong version of apache POI:
java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.getCellStyleAt(S)Lorg/apache/poi/ss/usermodel/CellStyle;
at org.jxls.transform.poi.PoiTransformer.clearCell(PoiTransformer.java:224)
at org.jxls.area.XlsArea.clearCells(XlsArea.java:437)
at org.jxls.builder.xls.XlsCommentAreaBuilder.build(XlsCommentAreaBuilder.java:181)
at org.jxls.template.SimpleExporter.gridExport(SimpleExporter.java:54)
Isn't it a bit strange that I have to explicitly include a dependency that another dependency depends upon? Moreover, how can I figure out which version of the dependency (the POI) I actually need?
I am just trying to get the simple exporter sample to work:
try (InputStream is = CalXlsExporter.class.getResourceAsStream(template)) {
try (OutputStream os2 = new FileOutputStream("ExportOutput.xlsx")) {
headers = Arrays.asList(HEADERS);
Context context = new Context();
context.putVar("headers", HEADERS);
context.putVar("cell", cal);
JxlsHelper.getInstance().processTemplate(is, os2, context); //Exception inside this
}
} catch (Exception e) {
e.printStackTrace();
}
You can always look at the Maven pom file of jxls-poi module for example you can see that jxls-poi-1.0.9 contains a dependency to POI 3.12 as defined in pom properties section
<properties>
...
<poi.version>3.12</poi.version>
...
</properties>
It may happen that later POI versions can also work but it is not always the case because it depends on Apache POI backwards compatibility.
I would try to simply remove the dependency on POI in your file as jxls will drag in the correct version of POI as transitive dependency anyway, so you just need to depend on jxls in your application always and future updates will not cause similar strange errors.

Rome 0.9 does not work correctly when module classloader order : parent last

Project description:
WebSphere Application Server 7.Maven project which uses Rome0.9.
<dependency>
<groupId>rome</groupId>
<artifactId>rome</artifactId>
<version>0.9</version>
</dependency>
I was solving the problem with log4j not logging. The problem was that log4j.properties were already set in parent project.
That's why I changed module's classloader order to Parent Last.
It fixed the problem with log4j, but application now throws following exception:
ParsingFeedException: Invalid XML
I've checked parent loaded libraries and they include the same version of Rome - 0.9.
It seems that I'm missing some dependencies in my project. I wonder if there is some way to find out which libraries are missing?
Maybe you could suggest any other solution?
I don't have a solution for searching missing loaded library.
However this workaround worked for me:
I reconfigured log4j in static block of main servlet class.
static Logger logger = LoggerFactory.getLogger(FeedAggregatorServlet.class);
static {
Properties p = new Properties();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
p.load(classLoader.getResourceAsStream("/FeedAggregatorlog4j.properties"));
} catch (IOException e) {
e.printStackTrace();
}
PropertyConfigurator.configure(p);
}

Hazelcast 3.4 IQueue offer

In Hazelcast 3.4, I am getting a NoSuchMethodError exception from using IQueue offer with time parameters. It works fine in Hazelcast 3.2. The code compiles and runs but when it executes the offer, it throws exception.
This is the method signature for BlockingQueue:
public boolean offer(E e, long l, TimeUnit tu) throws InterruptedException;
IQueue<GLBCSchema> queue=hzMQUtils.getQueue("myQueueName");
...
GLBCSchema tmpMsg=new GLBCSchema();
//queue.offer(tmpMsg); <=== works!
queue.offer(tmpMsg, 3, TimeUnit.SECONDS); <== throws NoSuchMethodError
Exception in thread "main" java.lang.NoSuchMethodError: com.hazelcast.core.IQueue.offer(Lgblx/gis/rtapi/facade/internal/GLBCSchema;JLjava/util/concurrent/TimeUnit;)Z
This is a bug or has Hazelcast removed this offer method?
Thx!
Never mind. I figured it out. After I removed the type declaration, it worked.
From:
IQueue<GLBCSchema> queue=hzMQUtils.getQueue("myQueueName");
To:
IQueue queue=hzMQUtils.getQueue("myQueueName");
I am not sure why they made this change. (Reference bug on JDK https://bugs.openjdk.java.net/browse/JDK-8064803)

Resources