Skip to content

programatic version is broken #37

Closed

Description

@noname713705

Actually, it is broken since log4j:log4j:1.2.15 and above.

The problem is that, due to error in the generated META-INF/MANIFEST.MF , it is not possible to determine the version of log4j / reload4j programatically.
This is due to an invalide Name: entry in the manifest.

This is a problem because it is then difficult to log, or access the reload4j version from code (for example, to check if you let the CVEs behind..)

  • version detection works with:
    Name: org/apache/log4j/
  • but is broken with the current:
    Name: org.apache.log4j

I'm not sure if I can make a pull request on reload4j, put the following git diff fixes the problem for me:

diff --git a/pom.xml b/pom.xml
index 1f54ec10..579cedc5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -202,11 +202,19 @@
         <version>${maven-jar-plugin.version}</version>
         <configuration>
           <archive>
+            <manifest>
+              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+            </manifest>
             <manifestEntries>
               <Multi-Release>true</Multi-Release>
               <X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
               <X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
             </manifestEntries>
+            <manifestSections>
+              <manifestSection>
+                <name>org/apache/log4j/</name>
+              </manifestSection>
+            </manifestSections>
             <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
           </archive>
         </configuration>

Sample code for programatically acessing the version (as for other maven artifacts), but only works with a built jar:

	@Test
	public void testLog4jVersion() {
		String implementationVersion = org.apache.log4j.PatternLayout.class.getPackage().getImplementationVersion();
		LOGGER.warn("log4j.version="+implementationVersion);
		assertNotNull(implementationVersion);
	}

Activity

  1. ceki commented on Feb 7, 2022

    @ceki
    Member

    The <addDefaultImplementationEntries>true</addDefaultImplementationEntries> is indeed useful.
    Regarding the PatternLayout.class.getPackage().getImplementationVersion(); call, once addDefaultImplementationEntries is effective, you do not need to add the name entry.

    Also note that, testLog4jVersion() test must be located outside the reload4j project/module to let the the jar plugin do its work.

  2. ceki commented on Feb 7, 2022

    @ceki
    Member

    Fixed in 7590700

  3. added this to the 1.2.19 milestone on Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions