stripe-java icon indicating copy to clipboard operation
stripe-java copied to clipboard

The source code for 20.128.0 is not what is compiled into classes

Open geniot opened this issue 2 years ago • 11 comments

Describe the bug

When trying to debug EventDataObjectDeserializer public Optional<StripeObject> getObject() I hit comment lines.

To Reproduce

  1. Using Maven add dependency 20.128.0
  2. Create a Java snippet: Event event = Webhook.constructEvent(json, header, endpointSecret); Optional<StripeObject> optional = event.getDataObjectDeserializer().getObject();
  3. Using Stripe CLI hit a webhook endpoint.
  4. Step into getDataObjectDeserializer.

Expected behavior

I expect to step through getObject method code.

Code snippets

@RequestMapping(value = "/stripeCheckoutSessionCompleted", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    @ResponseBody
    public String stripeWebhookEndpoint(HttpServletRequest request) {
        String header = request.getHeader("Stripe-Signature");
        try {
            String json = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
            Event event = Webhook.constructEvent(json, header, endpointSecret);
            Optional<StripeObject> optional = event.getDataObjectDeserializer().getObject();
...

OS

Windows 10

Java version

11

stripe-java version

20.128.0

API version

2020-08-27

Additional context

No response

geniot avatar Jun 12 '22 12:06 geniot

Hi @geniot ,

Thanks for the report. Sorry you're having problems here! Our team will investigate and report back!

dcr-stripe avatar Jun 28 '22 15:06 dcr-stripe

I'm not able to reproduce this, at least using Maven + IntelliJ.

My pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>MySampleStripeIntegration</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>18</maven.compiler.source>
        <maven.compiler.target>18</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>com.stripe</groupId>
            <artifactId>stripe-java</artifactId>
            <version>20.128.0</version>
        </dependency>
    </dependencies>

</project>

With this, I can debug and step through code such as:

            Event event = Webhook.constructEvent(json, header, endpointSecret);
            Optional<StripeObject> optional = event.getDataObjectDeserializer().getObject();

and see the underlying stripe-java source.

--

@geniot : Could you provide more information about your environment set up here? I suspect this is more likely a IDE/debugger configuration issue. At the very least, I've confirmed the source code that is shipped lines up with what is compiled with classes.

dcr-stripe avatar Jun 28 '22 15:06 dcr-stripe

@dcr-stripe , https://youtu.be/4dlLgrf9E1s Windows 10, Intellij 2021.2.4 Ultimate, default debug settings. Extract from Manifest: Manifest-Version: 1.0 Bnd-LastModified: 1654809243609 Bundle-ManifestVersion: 2 Bundle-Name: stripe-java Bundle-SymbolicName: stripe-java Bundle-Version: 20.128.0 Created-By: 18.0.1 (Azul Systems, Inc.) Export-Package: com.stripe;version="20.128.0"

geniot avatar Jun 28 '22 15:06 geniot

Interesting, this isn't reproducing for me.

I've seen this happen before if a package is accidentally pulling in multiple versions of stripe-java accidentally. Just confirming that you've done a clean rebuild (Build > Rebuild Project) here.

Could you also provide a bit more detail on your integration? Ideally the pom.xml, as well as any special settings you have in IntelliJ around which JDK you're using?

Thanks @geniot

dcr-stripe avatar Jun 28 '22 16:06 dcr-stripe

I've tried Java 11, Java 18, rebuilding. Created a new project with a basic pom.xml Same problem. I think it might be related to Lombok: https://stackoverflow.com/questions/36753524/library-source-does-not-match-the-bytecode-for-class

No special settings. Right now it's not that important for me. I just wanted to figure out how to replace getObject() marked as deprecated. I tried getDataObjectDeserializer().getObject() but it produced null. Unlike getObject(). So I tried to debug it. But ended up looking at comment lines. So I'll stick with the deprecated working method for now.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>

<groupId>stripe</groupId>
<artifactId>stripe</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>18</maven.compiler.source>
    <maven.compiler.target>18</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>com.stripe</groupId>
        <artifactId>stripe-java</artifactId>
        <version>20.128.0</version>
    </dependency>
</dependencies>

geniot avatar Jun 28 '22 16:06 geniot

Lombok is definitely an area to investigate. As of https://github.com/stripe/stripe-java/issues/555, we publish the delombok'ed sources, but perhaps something is wonky in that code path...

dcr-stripe avatar Jun 28 '22 17:06 dcr-stripe

I've drafted https://github.com/stripe/stripe-java/pull/1382 to try updating the lombok plugin. There appears to be some bug fixes in the lombok changelog around delombok output not matching.

Sorry for all the churn here. If you have a moment: would you be able to test with this branch, either by pulling it down and running./gradlew jar or by using the this JAR I've prebuilt at that branch (you'll need to unzip it)?

You can point the dependency to a local file by doing:


        <dependency>
            <groupId>com.stripe</groupId>
            <artifactId>stripe-java</artifactId>
            <version>20.130.0</version>
            <scope>system</scope>
            <systemPath>{PATH TO JAR}/stripe-java-20.130.0.jar</systemPath>
        </dependency>

dcr-stripe avatar Jun 28 '22 17:06 dcr-stripe

The zip at the link https://github.com/stripe/stripe-java/files/9003471/stripe-java-20.130.0.jar.zip does not have -sources.jar Maven downloads -sources.jar when I start debugging classes. There are 2 links at the top: download sources, decompile.

geniot avatar Jun 28 '22 17:06 geniot

@geniot sorry I haven't had a chance to investigate this further - I was wondering if you were still seeing this behavior on our latest releases?

dcr-stripe avatar Jul 25 '22 14:07 dcr-stripe

@dcr-stripe , just checked. Same jump to line 39 in EventData (where comments end). Using 20.135.0 It misses the line by 5. So my guess is that there are 5 lines above which are not counted. Lombok annotations?

geniot avatar Jul 26 '22 14:07 geniot

Thanks for trying @geniot ! I suspect the fix for #555 was not quite complete. On the "bright" side - I am now able to reproduce this as well.

From the plugin documentation:

In contrast to the javadoc task, the sourcesJar task is not adjusted to use the delomboked sources. This is done on purpose, so the line numbers in the -sources.jar match the LineNumberTable in the generated class files.

Likely switching to the delombok source, while making debugging easier, now caused this to be out of alignment.

If I revert https://github.com/stripe/stripe-java/pull/567/files, the problem is solved but then #555 happens again.

I'll continue looking if we can find a solution that solves both.

dcr-stripe avatar Jul 26 '22 16:07 dcr-stripe

Just chiming in here -- I'm being hit by this same issue, making it really hard to know what the root cause of deserialization is (likely some GSON oddity).

lightbody avatar Nov 05 '22 18:11 lightbody

Fixed in #1491 which will be released later this week.

richardm-stripe avatar Dec 13 '22 23:12 richardm-stripe

Released in https://github.com/stripe/stripe-java/releases/tag/v22.4.0

richardm-stripe avatar Dec 22 '22 20:12 richardm-stripe