twilio / twilio-java

A Java library for communicating with the Twilio REST API and generating TwiML.
MIT License
492 stars 429 forks source link

fix: drop reflective access warnings to java.time.* classes #596

Closed mjg123 closed 4 years ago

mjg123 commented 4 years ago

Java module system gives warnings on reflective access to java.time.* private fields, which are performed by Jackson when using TwilioRestClient.

Jackson provides a JavaTimeModule which configures an ObjectMapper to use public methods instead of reflective accesss to private fields in classes in java.time.

This PR adds the dependency for JavaTimeModule and adds it to the ObjectMapper created by TwilioRestClient, which removes all the warnings that I have seen.

Fixes #597

A short description of what this PR does.

Checklist

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

mjg123 commented 4 years ago

A note on testing:

Considering this code

package com.twilio.helperv8;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Helper8Warning {

    public static void main(String[] args) {
        Twilio.init(
            System.getenv("TWILIO_ACCOUNT_SID"),
            System.getenv("TWILIO_AUTH_TOKEN"));

        Message.creator(
            new PhoneNumber("<My phone number>"),
            new PhoneNumber("<My Twilio number>"),
            "Warning!"
        ).create();
    }
}

Without this patch - SMS is sent, 5 lines of warnings are sent to stderr:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.fasterxml.jackson.databind.util.ClassUtil (file:/home/mjg/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.3/jackson-databind-2.11.3.jar) to field java.time.ZonedDateTime.offset
WARNING: Please consider reporting this to the maintainers of com.fasterxml.jackson.databind.util.ClassUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

With this patch - SMS is sent, no warnings generated.

So I'm not sure how a unit test could be written for this.

mjg123 commented 4 years ago

Also raised as https://github.com/twilio/twilio-java/issues/597