You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "ritzow (via GitHub)" <gi...@apache.org> on 2024/04/07 07:05:11 UTC

[I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

ritzow opened a new issue, #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449

   ## Description
   
   I believe that adding `extends java.util.function.Supplier<T>` to `log4j-api/src/main/java/org/apache/logging/log4j/util/Supplier.java` may have caused binary or source code incompatibility with code compiled with previous versions of log4j. I am getting an exception. `java.lang.AbstractMethodError: Receiver class org.opensearch.discovery.PeerFinder$Peer$1$$Lambda/0x00007f13d3743af8 does not define or inherit an implementation of the resolved method 'abstract java.lang.Object get()' of interface java.util.function.Supplier.` 
   
   PeerFinder.Peer was compiled with an earlier version of log4j in which `MessageSupplier` did not inherit from `org.apache.logging.log4j.util.Supplier` and that class did not inherit from `java.util.function.Supplier`. I encountered this issue when using OpenSearch 2.13.0.
   
   Relevant commit: https://github.com/apache/logging-log4j2/commit/ffe06dd6507a64149e0e0bc3bbffaef575802fed
   
   ## Some assorted `javap` output:
   
   There's a lot more bytecode that could be inspected but I'm being lazy.
   
   The callsite in question:
   
   ```
   invokedynamic #91,  0             // InvokeDynamic #3:get:(Lorg/opensearch/discovery/PeerFinder$Peer$1;)Lorg/apache/logging/log4j/util/MessageSupplier;
   ```
   
   Bootstrap methods table:
   
   ```
     3: #178 REF_invokeStatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
       Method arguments:
         #168 ()Lorg/apache/logging/log4j/message/Message;
         #169 REF_invokeSpecial org/opensearch/discovery/PeerFinder$Peer$1.lambda$onFailure$0:()Lorg/apache/logging/log4j/message/Message;
         #168 ()Lorg/apache/logging/log4j/message/Message;
   
   ```
   
   javap output for the latest beta 2 MessageSupplier:
   
   Notice that there is no method definition since it is now inherited from `java.util.Supplier`! That's why the metafactory can't find the `get` method!
   
   Here's the newest, offending `MessageSupplier` class.
   
   ```
   Classfile /var/home/solomon/Downloads/MessageSupplier.class
     Last modified Feb 17, 2024; size 416 bytes
     SHA-256 checksum db9675cc665c17d2f99e71260492d7c9491770f1cbb0d17921c48064e3b6f4f2
     Compiled from "MessageSupplier.java"
   public interface org.apache.logging.log4j.util.MessageSupplier extends java.util.function.Supplier<org.apache.logging.log4j.message.Message>
     minor version: 0
     major version: 61
     flags: (0x0601) ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT
     this_class: #1                          // org/apache/logging/log4j/util/MessageSupplier
     super_class: #3                         // java/lang/Object
     interfaces: 1, fields: 0, methods: 0, attributes: 4
   Constant pool:
      #1 = Class              #2             // org/apache/logging/log4j/util/MessageSupplier
      #2 = Utf8               org/apache/logging/log4j/util/MessageSupplier
      #3 = Class              #4             // java/lang/Object
      #4 = Utf8               java/lang/Object
      #5 = Class              #6             // java/util/function/Supplier
      #6 = Utf8               java/util/function/Supplier
      #7 = Utf8               Signature
      #8 = Utf8               Ljava/lang/Object;Ljava/util/function/Supplier<Lorg/apache/logging/log4j/message/Message;>;
      #9 = Utf8               SourceFile
     #10 = Utf8               MessageSupplier.java
     #11 = Utf8               Deprecated
     #12 = Utf8               RuntimeVisibleAnnotations
     #13 = Utf8               Ljava/lang/Deprecated;
     #14 = Utf8               forRemoval
     #15 = Integer            1
     #16 = Utf8               since
     #17 = Utf8               3.0
   {
   }
   Signature: #8                           // Ljava/lang/Object;Ljava/util/function/Supplier<Lorg/apache/logging/log4j/message/Message;>;
   SourceFile: "MessageSupplier.java"
   Deprecated: true
   RuntimeVisibleAnnotations:
     0: #13(#14=Z#15,#16=s#17)
       java.lang.Deprecated(
         forRemoval=true
         since="3.0"
       )
   ```
   
   Here's the previous version from log4j 2.23, notice that it has the get() method defined :
   
   ```
   Classfile /var/home/solomon/Downloads/MessageSupplier.class
     Last modified Mar 6, 2024; size 202 bytes
     SHA-256 checksum c830019cc97f12778f0e0b8f7ffa9f58f2a50c2a788dd7da32c2d5edbcbe6621
     Compiled from "MessageSupplier.java"
   public interface org.apache.logging.log4j.util.MessageSupplier
     minor version: 0
     major version: 52
     flags: (0x0601) ACC_PUBLIC, ACC_INTERFACE, ACC_ABSTRACT
     this_class: #1                          // org/apache/logging/log4j/util/MessageSupplier
     super_class: #3                         // java/lang/Object
     interfaces: 0, fields: 0, methods: 1, attributes: 1
   Constant pool:
     #1 = Class              #2              // org/apache/logging/log4j/util/MessageSupplier
     #2 = Utf8               org/apache/logging/log4j/util/MessageSupplier
     #3 = Class              #4              // java/lang/Object
     #4 = Utf8               java/lang/Object
     #5 = Utf8               get
     #6 = Utf8               ()Lorg/apache/logging/log4j/message/Message;
     #7 = Utf8               SourceFile
     #8 = Utf8               MessageSupplier.java
   {
     public abstract org.apache.logging.log4j.message.Message get();
       descriptor: ()Lorg/apache/logging/log4j/message/Message;
       flags: (0x0401) ACC_PUBLIC, ACC_ABSTRACT
   }
   SourceFile: "MessageSupplier.java"
   ```
   
   ## Configuration
   
   **Version:** 3.0.0-beta2
   
   **Operating system:** Linux
   
   **JDK:** Oracle Corporation/OpenJDK 64-Bit Server VM/22/22+36-2370
   
   ## Logs
   
   ```
   java.lang.AbstractMethodError: Receiver class org.opensearch.discovery.PeerFinder$Peer$1$$Lambda/0x00007f13d3743af8 does not define or inherit an implementation of the resolved method 'abstract java.lang.Object get()' of interface java.util.function.Supplier.
   	at org.apache.logging.log4j.util.LambdaUtil.get(LambdaUtil.java:76)
   	at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2512)
   	at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:2246)
   	at org.apache.logging.log4j.spi.AbstractLogger.debug(AbstractLogger.java:342)
   	at org.opensearch.discovery.PeerFinder$Peer$1.onFailure(PeerFinder.java:443)
   	at org.opensearch.discovery.HandshakingTransportAddressConnector$1$1.onFailure(HandshakingTransportAddressConnector.java:201)
   	at org.opensearch.core.action.ActionListener$4.onFailure(ActionListener.java:192)
   	at org.opensearch.action.support.ThreadedActionListener$2.doRun(ThreadedActionListener.java:93)
   	at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:913)
   	at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
   	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
   	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
   	at java.base/java.lang.Thread.run(Thread.java:1570)
   ```
   ![image](https://github.com/apache/logging-log4j2/assets/11698787/cc73d9d0-a583-41db-81c6-f048ce9b0d1c)
   
   ## Reproduction
   
   I found this while trying to embed OpenSearch 2.13.0 into a java Maven project, with log4j 3.0.0-beta2. It's kind of annoying to set up, but I assume it could be done by calling the logger `debug` method with a lambda expression compiled with an earlier version of log4j.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "ritzow (via GitHub)" <gi...@apache.org>.
ritzow closed issue #2449: Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate
URL: https://github.com/apache/logging-log4j2/issues/2449


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz closed issue #2449: Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate
URL: https://github.com/apache/logging-log4j2/issues/2449


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449#issuecomment-2045801954

   I did some more testing and what happened is that in `3.0.0-beta2` we redefined `MessageSupplier` as:
   
   ```java
   public interface MessageSupplier extends Supplier<Message> {}
   ```
   
   which has **no methods** and inherits an abstract `Object get()` method.
   
   On the other hand in `2.24.0-SNAPSHOT` I defined `MessageSupplier` as:
   
   ```java
   public interface MessageSupplier extends Supplier<Message> {
       @Override
       Message get();
   }
   ```
   
   which has **two methods**: an abstract `Message get()` method and a default `Object get()` method.
   
   Was it luck or absolute master of Java binary compatibility rules? You'll never know :wink: .
   
   BTW: BND correctly identifies the first change as a **breaking** change:
   ```
   [ERROR]     MAJOR              INTERFACE  org.apache.logging.log4j.util.MessageSupplier
   [ERROR]       ADDED            IMPLEMENTS java.util.function.Supplier
   [ERROR]       ADDED            IMPLEMENTS org.apache.logging.log4j.util.Supplier
   [ERROR]       MAJOR            METHOD     get()
   [ERROR]         ADDED          RETURN     java.lang.Object
   [ERROR]         REMOVED        RETURN     org.apache.logging.log4j.message.Message
   ```
   
   We didn't notice it in `3.0.0-beta2`, because breaking changes are normal there.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "ritzow (via GitHub)" <gi...@apache.org>.
ritzow commented on issue #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449#issuecomment-2041349748

   @ppkarwasz I think I may have found a sneaky bug with a change you made.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449#issuecomment-2045959561

   >     * I could have bought this plan as a twilight state until we get rid off `MessageSupplier`, but we all know that removing stuff from `log4j-api` is a _"pipe dream"_.
   
   I wouldn't say that. Sure, I am not willing to publish a Log4j API 3.x for the next 10 or 20 years. But if a Jakarta Logging API comes along, it would certainly use `java.util.function.Supplier` instead of a custom type.
   
   As I remarked above, having a:
   
   ```java
       @Override
       Message get();
   ```
   
   code snippet pretty much removes the breaking change. As it was confirmed in [these comments](https://github.com/apache/logging-log4j2/commit/ffe06dd6507a64149e0e0bc3bbffaef575802fed#r140704013), the problem reported disappeared in `3.0.0-SNAPSHOT`.
   
   If we ever decide to remove the snippet abve, BND will detect it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on issue #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449#issuecomment-2046702649

   I am not strongly opinionated, but I suggest reverting the `MessageSupplier` change and only keeping the `@FunctionalInterface`. It increases complexity, brings marginal benefit, and, if (ever?) needed, can be done later.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449#issuecomment-2045090142

   @ritzow,
   
   Thank you for pointing out this problem. I was sure I left a comment two days ago, but AJAX must have eaten it.
   
   We did two apparently backward compatible changes in `3.x` and we backported them to `2.x`:
   
   1. We made `MessageSupplier` extend the standard `java.util.function.Supplier<Message>`,
   2. We made `o.a.l.l.util.Supplier` extends the standard `java.util.function.Supplier`.
   
   While the second one is **IMHO** completely backward compatible, the first one is problematic:
   
    - due to type erasure `Supplier<Message>` has a `get` method with descriptor `()Ljava.lang.Object;`,
    - `MessageSupplier` has a `get` method with descriptor `()Lorg.apache.logging.log4j.message.Message;`.
   
   If we cast a `MessageSupplier` to `Supplier` and call `get` (this is what happens in `3.0.0-beta2`), we incur in a linkage error. @jvz, do you agree with this diagnosis? Should we revert the changes to `MessageSupplier`, but keep those to `o.a.l.l.util.Supplier`? Or should we revert both changes?
   
   BTW: I am curious why BND didn't pick this up as breaking change, maybe I should open a bug report.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "jvz (via GitHub)" <gi...@apache.org>.
jvz commented on issue #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449#issuecomment-2045575558

   BND might not have noticed because it's a strange edge case involving type erasure and default methods.
   
   I think we should revert the `MessageSupplier` changes since the API is staying with the 2.x semantic version. Assuming the `util.Supplier` interface works as expected, I think we can keep that change.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Lambda expressions compiled with a previous version of `org.apache.logging.log4j.util.Supplier.java` or `MessageSupplier` fail to generate (logging-log4j2)

Posted by "vy (via GitHub)" <gi...@apache.org>.
vy commented on issue #2449:
URL: https://github.com/apache/logging-log4j2/issues/2449#issuecomment-2045930917

   @jvz, @ppkarwasz, as I understand from Piotr's explanation, the rationale behind this change is to allow several `MessageSupplier` usages in `log4j-core` to switch to `Supplier<Message>` instead. I suggest reverting the change making `MessageSupplier` extend from `Supplier<Message>`, because...
   
   - I don't see much value in this, since `log4j-core` usages are pretty much internal code sites and it doesn't matter if they use a native Java interface or not.
   - Since we placed a `@FunctionalInterface` there, user have sufficient freedom to interact with it.
   - Before, we only had `MessageSupplier`. Now, we have both `MessageSupplier` and `Object Supplier#get()`. I think the complexity is increased without much benefit.
   - I could have bought this plan as a twilight state until we get rid off `MessageSupplier`, but we all know that removing stuff from `log4j-api` is a _"pipe dream"_.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org