How to solve java.lang.NoSuchFieldError: EMPTY_BYTE_ARRAY
When deploying applications on WildFly, encountering a log4j2 core libs and log4j2 API mismatch issue is not uncommon. This issue, presented as java.lang.NoSuchFieldError: EMPTY_BYTE_ARRAY, arises due to discrepancies between the Log4j2 core libraries used within the application and the Log4j2 API provided by WildFly’s modules.
Cause:
Firstly, the mismatch occurs when the application uses a specific version of Log4j2 core libraries that conflicts with the Log4j2 API provided by WildFly. This conflict leads to inconsistencies and NoSuchFieldError or other runtime errors related to Log4j2 components:
Solution:
To resolve the Log4j2 core and API mismatch in WildFly, follow these steps:
- Identify Versions: Firstly, check and verify the Log4j2 core library version used within the application and the Log4j2 API provided by WildFly.
- Exclude Module: Then, create or update the
jboss-deployment-structure.xmlfile within thesrc/main/webapp/WEB-INF/directory of the application. Exclude theorg.apache.logging.log4j.apimodule to prevent the server from using its Log4j2 API module. Example snippet:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.logging.log4j.api"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
Test and Validate: After making these adjustments, thoroughly test the application to ensure that the Log4j2 core and API are in sync and functioning without any runtime errors.
To learn how configure Log4j 2 properly on WildFly we recommend checking this article: How to use Log4j2 in your WildFly applications
Conclusion:
Resolving the Log4j2 core and API mismatch in WildFly involves aligning the Log4j2 core libraries within the application with the Log4j2 API provided by the server. By excluding conflicting modules and ensuring version compatibility, the application can function seamlessly within the WildFly environment without runtime issues related to Log4j2.
This approach helps maintain consistency and stability in logging functionalities, ensuring a smoother deployment experience on WildFly.
Recommended Articles
Enable Logs Compression in WildFly Using Periodic Rotating File Handler and Log4j2
Learn how to compress logs in WildFly using the Periodic Rotating File Handler or Log4j2. #WildFly #JavaLogging #LogCompression
High Availability with WildFly: Ensuring Java EE App Uptime and Performance
Learn how to configure high availability in WildFly, a robust framework for Java EE applications. Discover the role of failover, load balancing, and other subsystems in ensuring seamless application operation.
Fix Error 'Unsupported protocol: remote+http' When Connecting via JMX to WildFly/WildFly Application Server
Learn how to fix the error 'Unsupported protocol: remote+http' when connecting via JMX to a WildFly application server. Includes code snippet and dependency details.
Install and Use WildFly Core as Management Interface for Remote Servers
Learn how to install and utilize WildFly core as a management interface for remote WildFly servers, including installation via Galleon and using the CLI.