You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "John Vasileff (JIRA)" <ji...@apache.org> on 2011/09/19 03:10:10 UTC

[jira] [Created] (LOG4J2-51) ClassCastException in Category logger

ClassCastException in Category logger
-------------------------------------

                 Key: LOG4J2-51
                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
             Project: Log4j 2
          Issue Type: Bug
          Components: log4j 1.2 emulation
            Reporter: John Vasileff
            Priority: Blocker


When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.

See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Updated] (LOG4J2-51) ClassCastException in Category logger

Posted by "John Vasileff (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

John Vasileff updated LOG4J2-51:
--------------------------------

    Attachment: 0003-remove-dangerous-logger-factory-override.patch

Attaching patch #3 in the series:

remove dangerous logger factory override

Remove LoggerContext support for custom logger factories.  All Loggers returned
by LoggerContext should be compatibile and of the same type.

In the following:

Logger getLogger(LoggerFactory factory, String name)

the returned Logger was not guaranteed to be created by the provided factory.
The value of specifying a custom logger is diminished without this guarantee.

Since only one instance of each logger exists, behavior should not be defined
by the caller of getLogger() that "wins" the race to be the one to determine
the factory used to create the logger.


> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Updated] (LOG4J2-51) ClassCastException in Category logger

Posted by "John Vasileff (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

John Vasileff updated LOG4J2-51:
--------------------------------

    Attachment: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch

Attached test case for this issue.

> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Commented] (LOG4J2-51) ClassCastException in Category logger

Posted by "Ralph Goers (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13114494#comment-13114494 ] 

Ralph Goers commented on LOG4J2-51:
-----------------------------------

Unfortunately, this patch breaks the ClassLoaderContextSelector as it will now not be able to determine what ClassLoader the Logger should be associated with.

> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Updated] (LOG4J2-51) ClassCastException in Category logger

Posted by "John Vasileff (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

John Vasileff updated LOG4J2-51:
--------------------------------

    Attachment: 0002-fix-for-Category.getInstance-returning-cached-Logger.patch

Patch to fix the problem.  Commit notes:

fix for Category.getInstance returning cached Logger

When creating new Category instances, the Category class passed a custom
Factory to context.getLogger(factory, name).  The factory created loggers of
type CategoryFactory.CategoryLogger, and code in the Category class casted the
logger to this type.

The problem was that context.getLogger(factory, name) only uses the provided
factory if it has to create a new logger.  Cached loggers would simply be
returned.  If the cached logger was created using a different factory, it was
not of type CategoryFactory.CategoryLogger and a ClassCastException would occur
during operations that called isEnabledFor or forcedLog.


> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Commented] (LOG4J2-51) ClassCastException in Category logger

Posted by "John Vasileff (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13114739#comment-13114739 ] 

John Vasileff commented on LOG4J2-51:
-------------------------------------

Yes, the patch in LOG4J2-50 is required to fix CategoryTest.testClassName().

Where is the ClassCastException occurring?  I wonder if this is due to some interaction between the IDE and mvn build where a mix of old and new versions are being used.  Something like this happened to me, but after clean, etc., it cleared up.

$ git log --oneline | head
276d6e1 cleanup FQCN code
bac5439 remove dangerous logger factory override
12a7861 fix for Category.getInstance returning cached Logger
d6e9975 add test for Category when using a log4j2 Logger
2db42d3 Enhance comments on getThrowable
cdc19e5 Test that class name in log message is correct

$ mvn clean test
...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Apache Log4j 2 ........................................ SUCCESS [1.454s]
[INFO] Log4J API ............................................. SUCCESS [2.689s]
[INFO] Log4J2 Core ........................................... SUCCESS [1:03.924s]
[INFO] Log4J Compatibility API ............................... SUCCESS [3.471s]
[INFO] SLF4J Binding ......................................... SUCCESS [2.244s]
[INFO] Log4J2 Commons Logging ................................ SUCCESS [1.964s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 16 seconds
[INFO] Finished at: Mon Sep 26 11:55:33 EDT 2011
[INFO] Final Memory: 37M/265M
[INFO] ------------------------------------------------------------------------

$ cat log4j12-api/target/surefire-reports/org.apache.log4j.CategoryTest.txt 
-------------------------------------------------------------------------------
Test set: org.apache.log4j.CategoryTest
-------------------------------------------------------------------------------
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.657 sec


> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Resolved] (LOG4J2-51) ClassCastException in Category logger

Posted by "Ralph Goers (Resolved) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ralph Goers resolved LOG4J2-51.
-------------------------------

    Resolution: Fixed
      Assignee: Ralph Goers

Patch was applied. Please verify and close.
                
> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Assignee: Ralph Goers
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: [jira] [Updated] (LOG4J2-51) ClassCastException in Category logger

Posted by Ralph Goers <ra...@dslextreme.com>.
John, I don't want you to think I am ignoring this.  I've been at a conference this week and have been a little bit tight for time. I plan on looking at this and LOG4J2-50 in the next couple of days.  Hopefully your patch will fix it.

Ralph

On Sep 18, 2011, at 6:28 PM, John Vasileff (JIRA) wrote:

> 
>     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
> 
> John Vasileff updated LOG4J2-51:
> --------------------------------
> 
>    Attachment:     (was: 0002-fix-for-Category.getInstance-returning-cached-Logger.patch)
> 
>> ClassCastException in Category logger
>> -------------------------------------
>> 
>>                Key: LOG4J2-51
>>                URL: https://issues.apache.org/jira/browse/LOG4J2-51
>>            Project: Log4j 2
>>         Issue Type: Bug
>>         Components: log4j 1.2 emulation
>>           Reporter: John Vasileff
>>           Priority: Blocker
>>        Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>> 
>> 
>> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
>> See LOG4J2-50 for additional symptoms.
> 
> --
> This message is automatically generated by JIRA.
> For more information on JIRA, see: http://www.atlassian.com/software/jira
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Updated] (LOG4J2-51) ClassCastException in Category logger

Posted by "John Vasileff (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

John Vasileff updated LOG4J2-51:
--------------------------------

    Attachment:     (was: 0002-fix-for-Category.getInstance-returning-cached-Logger.patch)

> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Updated] (LOG4J2-51) ClassCastException in Category logger

Posted by "Ralph Goers (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ralph Goers updated LOG4J2-51:
------------------------------

    Comment: was deleted

(was: Unfortunately, this patch breaks the ClassLoaderContextSelector as it will now not be able to determine what ClassLoader the Logger should be associated with.)

> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Commented] (LOG4J2-51) ClassCastException in Category logger

Posted by "Ralph Goers (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13114516#comment-13114516 ] 

Ralph Goers commented on LOG4J2-51:
-----------------------------------

I applied the patches above and LogManager.getLogger() is still throwing a ClassCastException. In addition a second unit test is failing but I believe you said that error is fixed by the patch for LOG4J2-50.

> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Updated] (LOG4J2-51) ClassCastException in Category logger

Posted by "John Vasileff (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

John Vasileff updated LOG4J2-51:
--------------------------------

    Attachment: 0002-fix-for-Category.getInstance-returning-cached-Logger.patch

re-attaching....

> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


[jira] [Closed] (LOG4J2-51) ClassCastException in Category logger

Posted by "John Vasileff (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOG4J2-51?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

John Vasileff closed LOG4J2-51.
-------------------------------

    
> ClassCastException in Category logger
> -------------------------------------
>
>                 Key: LOG4J2-51
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-51
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: log4j 1.2 emulation
>            Reporter: John Vasileff
>            Assignee: Ralph Goers
>            Priority: Blocker
>         Attachments: 0001-add-test-for-Category-when-using-a-log4j2-Logger.patch, 0002-fix-for-Category.getInstance-returning-cached-Logger.patch, 0003-remove-dangerous-logger-factory-override.patch
>
>
> When a Category is "created" with the same name as a previously created log4j2 Logger, a ClassCastException occurs when calling category.l7dlog(...) and others.
> See LOG4J2-50 for additional symptoms.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org