openpreserve / jhove

File validation and characterisation.
http://jhove.openpreservation.org
Other
161 stars 78 forks source link

{0} is a magic number. #426

Open carlwilson opened 5 years ago

carlwilson commented 5 years ago

There are more than 1400 occurrences of this issue. Why is this an issue? Since Checkstyle 3.1

Checks that there are no "magic numbers" where a magic number is a numeric literal that is not defined as a constant. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

It is fine to have one constant defining multiple numeric literals within one expression:

static final int SECONDS_PER_DAY = 24 * 60 * 60;
static final double SPECIAL_RATIO = 4.0 / 3.0;
static final double SPECIAL_SUM = 1 + Math.E;
static final double SPECIAL_DIFFERENCE = 4 - Math.PI;
static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42);

A full list of all occurrences on codacy can be found here

Not all numbers will need "fixing", for a decent guide on refactoring taste see: https://refactoring.guru/replace-magic-number-with-symbolic-constant/. This example: https://help.semmle.com/wiki/display/JAVA/Magic+numbers shows the use of public static class constants as opposed to method level constants.

You can find all occurrences of this issue here on Codacy.

marti1125 commented 4 years ago

Hi @carlwilson I would like to work in this issue

carlwilson commented 4 years ago

@marti1125, you have your way, be careful what you wish for ;)

MartinSpeller commented 4 years ago

{0} is a magic number. #426 Assigned to marti1125 (Willy)