oracle - Why Java LogRecord constructor calls a random method to check non null parameter? -


the constructor of class java.util.logging.logrecord(level level, string msg) explains explicitly in code in first line invokes random line of code check variable level not null.

// make sure level isn't null, calling random method.

are there hidden explanations this?

here screenshot of constructor can check directly ide.

logrecord

it example of implicit null check.

even though comment says 'random method' getclass() chosen because:

  1. it shorter writing explicit if check null , throwing new nullpointerexception. on other hand there long comment explaining short code.
  2. it free of side effects.
  3. it declared final , can't overridden subclass.
  4. the code written prior java.util.objects.requirenonnull.

Comments