Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obscure field and modifier in Log4j Logger

Tags:

java

bytecode

When looking into the class file for org.apache.log4j.Logger it defines a synthetic field of type Class with name class$org$apache$log4j$Logger.

From looking at the byte code, it is clear that this field represents the self-referenced class from a time where the constant pool could not yet reference types. What I do however find strange is the modifier of this field which is 0x41008 which indicates a private, synthetic field (that I can follow) but which adds a modifier 0x40000 which I cannot find documented anywhere.

Where does this modifier at bit 19 come from and what does it express? (Log4j is compiled for Java 1).

like image 487
Rafael Winterhalter Avatar asked Apr 14 '16 20:04

Rafael Winterhalter


People also ask

What are the three most important components of log4j?

log4j has three main components: loggers: Responsible for capturing logging information. appenders: Responsible for publishing logging information to various preferred destinations. layouts: Responsible for formatting logging information in different styles.

What is PatternLayout in log4j2?

PatternLayout to format your logging information. The PatternLayout class extends the abstract org. apache. log4j. Layout class and overrides the format() method to structure the logging information according to a supplied pattern.


Video Answer


1 Answers

javap is perfectly happy with that class file:

  static java.lang.Class class$org$apache$log4j$Logger;
    descriptor: Ljava/lang/Class;
    flags: ACC_STATIC
    Synthetic: true

access_flags are supposed to be u2, meaning 2-byte unsigned. It is puzzling to see 0x41008, which is larger than u2. Some tools are known to store access_flags in larger types, and inject auxiliary bits (ASM does it, JVMs do it, etc.) I know you are reading with ASM, so this is probably what you are looking at:

org/objectweb/asm/ClassReader.java:

        } else if ("Synthetic".equals(attrName)) {
            access |= Opcodes.ACC_SYNTHETIC
                    | ClassWriter.ACC_SYNTHETIC_ATTRIBUTE;

org/objectweb/asm/ClassWriter.java:

/**
 * Pseudo access flag to distinguish between the synthetic attribute and the
 * synthetic access flag.
 */
static final int ACC_SYNTHETIC_ATTRIBUTE = 0x40000;

The question is, how does it leak to you...

like image 136
Aleksey Shipilev Avatar answered Oct 16 '22 23:10

Aleksey Shipilev