hi, We are using poi-4.0.1 to extract office properties. However, we are getting the below ClassCastException while performing the extraction. Could you please help ? Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class org.apache.poi.hpsf.CustomProperty (java.lang.String is in module java.base of loader 'bootstrap'; org.apache.poi.hpsf.CustomProperty is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @71092212) at com.emc.o2.api.config.modules.attribute.extract.O2ExtractOffice2003.getAttributesFromFile(O2ExtractOffice2003.java:97) Regards, Sushmita
Hi Sushmita, please also upload your example file otherwise we can't validate/fix this issue. Andi
Created attachment 36517 [details] Issue related to ClassCastException which we are facing while using poi-4.0.1 along with java 11
Code causing classcastexception: CustomProperty property = (CustomProperty) e.getValue(); CustomProperties newCustomProperties = dsi.getCustomProperties(); Iterator iterator = customProperties.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry e = (Map.Entry) iterator.next(); CustomProperty property = (CustomProperty) e.getValue(); String name = property.getName(); Object oldValue = property.getValue(); }
hi Andrea, Could you please provide us information on the same ? Regards, Sushmita
Sushmita - where does the code from your comment of 2019-04-10 09:43:14 UTC come from? If it is your code, then you shouldn't be doing a class cast. You should check if the value is an instanceof CustomProperty before casting it.
From the JavaDoc of CustomProperties: While this class is roughly HashMap<Long,CustomProperty>, that's the internal representation. To external calls, it should appear as HashMap<String,Object> mapping between Names and Custom Property Values. I think, this is enough explaining the error - I'm closing this now as "invalid".