This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 179297 - "Inefficient to use string concat in logger" usually noise for INFO/WARNING/SEVERE
Summary: "Inefficient to use string concat in logger" usually noise for INFO/WARNING/S...
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 6.x
Hardware: PC Linux
: P4 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-01-07 14:32 UTC by Jesse Glick
Modified: 2016-07-07 07:18 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2010-01-07 14:32:59 UTC
For log levels of INFO or higher, a typically configured application will always format the log record for some handler (stderr by default), in which case precomputing the log message bears no additional cost. Example in Hudson which I would not care to change according to the supplied fix:

LOGGER.warning("Interrupted update of lastSuccessful/lastStable symlinks for " + getProject().getDisplayName());

Since creating a message format often results in less readable code, I would suggest disabling the hints in these cases, or showing it on the current line only.

What would be useful (mainly on CONFIG or lower) is a check for method calls in any of the format parameters. In the above example, either getProject() or getDisplayName() could be expensive calls. (In this case they are probably very cheap, but this is not trivial to tell from code inspection.) In such a case, assuming the parameters cannot be replaced with simple field accesses, the best approach is to wrap the whole log statement in

if (LOGGER.isLoggable(Level.WARNING)) {...}
Comment 1 Martin Balin 2016-07-07 07:18:34 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss