Skip to content

Logger.getName() cause exceptionΒ #220

@SgtOmer

Description

@SgtOmer

When trying to convert the following sample class:

public class Main {
    private static final Logger logger = LogManager.getLogger();

    static public void main(String[] args) {
        logger.debug(logger.getName());
    }
}

A ConversionException is thrown:
org.apache.logging.log4j.weaver.ConversionException: Unsupported method 'org.apache.logging.log4j.Logger#getName'.

Based on the stack trace a located the bug to be in the LoggerConversionHandler in the handleMethodInstruction method.
It seems the default operation to an unplanned function is to throw exception instead of keeping the call as is. There is already a section in the switch for this kind of calls, so creating the NOP as the default will also remove a bit of bloat and support more functions. My suggestion is simple:

default:
  // These are NOPs
  mv.invokeInterface(LOGGER_TYPE, new Method(name, descriptor));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions