Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7726763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:17:50+00:00 2026-06-01T05:17:50+00:00

Consider the following class definitions: import com.codahale.logula.Logging abstract class A extends Logging { log.info(from

  • 0

Consider the following class definitions:

import com.codahale.logula.Logging
abstract class A extends Logging { log.info("from A") }
class C extends A { log.info("from C") }

They use Logula, a great logging library for Scala.

Creating an object of class C works great:

new C()

and produces the expected output:

INFO  [2012-03-31 19:16:14,261] C: from A
INFO  [2012-03-31 19:16:14,263] C: from C

But creating an instance of an anonymous sub-class of A

new A() {}

throws a NullPointerException:

Exception in thread "main" java.lang.NullPointerException
    at com.codahale.logula.Log$.clean(Log.scala:25)
    at com.codahale.logula.Log$.forName(Log.scala:23)
    at com.codahale.logula.Log$.forClass(Log.scala:18)
    at com.codahale.logula.Logging$class.log(Logging.scala:172)
    at A.log(LoggingTraitTest.scala:3)
    at A.<init>(LoggingTraitTest.scala:3)
    at LoggingTraitTest$$anon$1.<init>(LoggingTraitTest.scala:8)
    at LoggingTraitTest$delayedInit$body.apply(LoggingTraitTest.scala:8)
    at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App$$anonfun$main$1.apply(App.scala:60)
    at scala.App$$anonfun$main$1.apply(App.scala:60)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
    at scala.App$class.main(App.scala:60)
    at LoggingTraitTest$.main(LoggingTraitTest.scala:6)
    at LoggingTraitTest.main(LoggingTraitTest.scala)

A similar exception is thrown if an anonymous sub-class of C is instantiated: new C() {}

Why is there any difference between an explicit and an anonymous class instantiation here?

Any hint about how I could find out what is happening would be welcome. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:17:52+00:00Added an answer on June 1, 2026 at 5:17 am

    The problem is that Logula wants a canonical name for the class, which doesn’t exist for anonymous classes. See for example the documentation for Class.getCanonicalName:

    Returns the canonical name of the the underlying class as defined by
    the Java Language Specification. Returns null if the underlying class
    does not have a canonical name (i.e., if it is a local or anonymous
    class or an array whose component type does not have a canonical
    name).

    So it looks like you’re out of luck on this one, but if you really, really needed to be able to use logging with anonymous classes, you could replace getCanonicalName with getSimpleName in the following line (18) of Log.scala in the Logula source:

    def forClass(klass: Class[_]) = forName(klass.getCanonicalName)
    

    This gives me the following output:

    0    [main] INFO  C  - from A
    1    [main] INFO  C  - from C
    1    [main] INFO  anon.2  - from A
    2    [main] INFO  anon.1  - from A
    2    [main] INFO  anon.1  - from C
    

    Which is more or less what you want, probably. I’m not familiar enough with Logula to know whether this change would introduce headaches down the line, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about .net generics. Consider the following code: public abstract class
Consider following example: class CBase abstract { protected: CBase() { } }; I could
Consider the following definitions: class Foo a where foo :: a -> Int class
Consider the following class definitions class of2010(object): def __init__(self): self._a = 1 self._b =
Consider the following class definition: class StrToTokens { StrToTokens(const char* str, const char* delimiters
Consider the following class hierarchy: public class Foo { public string Name { get;
Consider the following class public class Class1 { public int A { get; set;
consider the following class: class Order { int OrderId {get; set;} int CustomerId {get;
Consider the following code: class A { public: virtual void f() throw ( int
Consider the following code: class A { public: A& operator=( const A& ); const

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.