Bug 63332 - Issue related to ClassCastException which we are facing while using poi-4.0.1 along with java 11.
Summary: Issue related to ClassCastException which we are facing while using poi-4.0.1...
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: HPSF (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-10 08:16 UTC by Sushmita Nag
Modified: 2019-04-10 21:11 UTC (History)
0 users



Attachments
Issue related to ClassCastException which we are facing while using poi-4.0.1 along with java 11 (26.50 KB, application/msword)
2019-04-10 09:41 UTC, Sushmita Nag
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sushmita Nag 2019-04-10 08:16:49 UTC
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
Comment 1 Andreas Beeker 2019-04-10 08:19:31 UTC
Hi Sushmita,

please also upload your example file otherwise we can't validate/fix this issue.

Andi
Comment 2 Sushmita Nag 2019-04-10 09:41:26 UTC
Created attachment 36517 [details]
Issue related to ClassCastException which we are facing while using poi-4.0.1 along with java 11
Comment 3 Sushmita Nag 2019-04-10 09:43:14 UTC
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();
            }
Comment 4 Sushmita Nag 2019-04-10 11:30:21 UTC
hi Andrea,

Could you please provide us information on the same ?

Regards,
Sushmita
Comment 5 PJ Fanning 2019-04-10 12:24:51 UTC
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.
Comment 6 Andreas Beeker 2019-04-10 21:11:09 UTC
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".