IABTechLab / iabgpp-java

Apache License 2.0
11 stars 12 forks source link

ClassCastException / API Mismatch #17

Closed ym-corey closed 2 months ago

ym-corey commented 1 year ago

Hi,

This code:

gppModel.setFieldValue(TcfEuV2.NAME, TcfEuV2Field.PURPOSE_CONSENTS, new ArrayList<>(List.of(1)));

Results in the following exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at com.intellij.junit5.JUnit5TestRunnerUtil.loadMethodByReflection(JUnit5TestRunnerUtil.java:124)
    at com.intellij.junit5.JUnit5TestRunnerUtil.buildRequest(JUnit5TestRunnerUtil.java:100)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:43)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
    at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Boolean (java.lang.Integer and java.lang.Boolean are in module java.base of loader 'bootstrap')
    at com.iab.gpp.encoder.datatype.encoder.FixedBitfieldEncoder.encode(FixedBitfieldEncoder.java:16)
    at com.iab.gpp.encoder.datatype.EncodableFixedBitfield.encode(EncodableFixedBitfield.java:23)
    at com.iab.gpp.encoder.section.AbstractEncodableSegmentedBitStringSection.encodeSegmentsToBitStrings(AbstractEncodableSegmentedBitStringSection.java:49)
    at com.iab.gpp.encoder.section.TcfEuV2.encode(TcfEuV2.java:148)
    at com.iab.gpp.encoder.GppModel.encode(GppModel.java:201)

It seems that PURPOSE_CONSENTS is expecting a List<Boolean> when being set, however the return API (gppModel.getTcfEuV2Section().getPurposeConsents()) tries to respond with a List<Integer>. But the values are actually Boolean values (as that is what we set).

ym-corey commented 1 year ago

If you attempt to access the gppModel.getTcfEuV2Section().getPurposeConsents() you receive the following ClassCastException:

java.lang.ClassCastException: class java.lang.Boolean cannot be cast to class java.lang.Integer (java.lang.Boolean and java.lang.Integer are in module java.base of loader 'bootstrap')
chuff commented 1 year ago

Fixed in 3.0.7