Skip to content

Fix some unnecessary use of boxed types and incorrect format strings spotted by lgtm.#4474

Merged
gianm merged 15 commits intoapache:masterfrom
chrisgavin:boxed-variables-and-format-strings
Jul 13, 2017
Merged

Fix some unnecessary use of boxed types and incorrect format strings spotted by lgtm.#4474
gianm merged 15 commits intoapache:masterfrom
chrisgavin:boxed-variables-and-format-strings

Conversation

@chrisgavin
Copy link
Copy Markdown
Contributor

This pull request fixes some small problems identified by lgtm. You can find more details here.

The first commit changes some boxed types which can never be null to unboxed types.

The second commit fixes some format strings where the number of arguments doesn't match the number of placeholders in the format string.

@jihoonson
Copy link
Copy Markdown
Contributor

@chrisgavin thanks for your patch. Please check the compilation error.

@chrisgavin chrisgavin force-pushed the boxed-variables-and-format-strings branch from 57bc4ae to 1f659c5 Compare June 30, 2017 17:27
@chrisgavin chrisgavin force-pushed the boxed-variables-and-format-strings branch from 1f659c5 to dc014e6 Compare July 1, 2017 10:17
@chrisgavin chrisgavin force-pushed the boxed-variables-and-format-strings branch from dc014e6 to 7e9a322 Compare July 2, 2017 22:37
@chrisgavin
Copy link
Copy Markdown
Contributor Author

Thanks. I have fixed it. :)

@leventov
Copy link
Copy Markdown
Member

leventov commented Jul 3, 2017

@chrisgavin please in the future, don't amend commits in your PR, always add new commits on top, including merge commits.

@chrisgavin
Copy link
Copy Markdown
Contributor Author

@leventov Sorry about that. I could revert to the previous HEAD of this PR and then make the compilation fix as a new commit if that would be helpful.

@leventov
Copy link
Copy Markdown
Member

leventov commented Jul 3, 2017

@chrisgavin not needed now, it's for the future.

Also could you please add inspections for this kind of errors?

  1. Add to Druid.xml:
    <inspection_tool class="MalformedFormatString" enabled="true" level="ERROR" enabled_by_default="true">
      <option name="additionalClasses" value="io.druid.java.util.common.StringUtils,io.druid.java.util.common.logger.Logger" />
      <option name="additionalMethods" value="trace,debug,info,warn,error,wtf,format,nonStrictFormat" />
    </inspection_tool>
  1. Add to checkstyle.xml:
    <module name="Regexp">
      <property name="format" value="com\.metamx\.common\.logger"/>
      <property name="illegalPattern" value="true"/>
      <property name="message" value="Use io.druid.java.util.common.logger.Logger instead"/>
    </module>
  1. I cannot find an inspection for unecessary use for boxed types (there is "unnecessary boxing" but it doesn't spot the places that you have found), but maybe there is some.

@leventov leventov added the Bug label Jul 3, 2017
@leventov
Copy link
Copy Markdown
Member

leventov commented Jul 3, 2017

Or more generally, you may prohibit any non-druid loggers by regex like

(?<!io.druid.java.util.common.logger)\.Log(ger)?[^A-Za-z0-9]

But a few exceptions will be needed, that you may guard with //CHECKSTYLE.OFF: Regexp and //CHECKSTYLE.ON: Regexp comments.

@leventov
Copy link
Copy Markdown
Member

leventov commented Jul 4, 2017

@chrisgavin it wasn't supposed to be clean, please fix inspection and checkstyle failures now.

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
//CHECKSTYLE.OFF: Regexp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why needs to use old logger?

import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
//CHECKSTYLE.OFF: Regexp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why needs to use old logger?

log.warn(message);
}

/** @noinspection MalformedFormatString */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use SuppressWarnings


import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
//CHECKSTYLE.OFF: Regexp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why needs to use old logger?

import com.google.common.collect.Sets;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
//CHECKSTYLE.OFF: Regexp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why needs to use old logger?

@chrisgavin
Copy link
Copy Markdown
Contributor Author

@leventov The places that still use the old logger do so because the logger is passed into a LoggingEmitter constructor, which only accepts a metamx logger.

@leventov
Copy link
Copy Markdown
Member

leventov commented Jul 6, 2017

public Result<T> apply(Cursor input)
{
log.debug("Running over cursor[%s]", adapter.getInterval(), input.getTime());
log.debug("Running over cursor[%s]", input.getTime());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange logging "cursor[input.getTime()]". Also maybe just remove this debugging line

}
catch (Exception e) {
log.warn(e, "Could not close aggregator, skipping.", aggregator);
log.warn(e, "Could not close aggregator, skipping.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not print the aggregator?

public Result<TopNResultValue> apply(Cursor input)
{
log.debug("Running over cursor[%s]", adapter.getInterval(), input.getTime());
log.debug("Running over cursor[%s]", input.getTime());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@leventov
Copy link
Copy Markdown
Member

leventov commented Jul 7, 2017

@chrisgavin also please fill the CLA http://druid.io/community/cla.html

@gianm gianm added this to the 0.11.0 milestone Jul 13, 2017
@gianm gianm merged commit 960cb07 into apache:master Jul 13, 2017
@chrisgavin chrisgavin deleted the boxed-variables-and-format-strings branch July 14, 2017 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants