I'd like to propose the following RFE for the magic
Add a property "ignoreContext" where magic number
checks will be suppressed. The ignoreContext would take
a list of possible values:
1) RHS of static initializes. This permits initializes like:
static final int BUF_SIZE = 8*1024;
static final State START = new State(1);
etc. The justification for ignoring this context is that
such magic numbers are magic, but that's OK (for some
users). There can be some complications involving
embedded class definitions as pointed out by Lars.
Still, it seems relatively easy to implement.
2) In the body of the hashCode method. The
justification for ignoring this context is that hash
function implementation commonly contain prime
numbers which are magic - but that's OK (for some
users). This one seems easy to implement - since the
hashCode method is a specific well known method on
3) In initializes for the default size of HashTables, etc.
These magic numbers are not as dangerous as magic
numbers which reflect the fixed size of a table.
This one seems harder to implement, maybe
ignoreContext would specify "constructorArgument" and
another property could specify a list of constructors it
The intent of all of the above is to reduce the number of
unimportant (or less important) magic number reports so
that it's tractable to actually run with this check turned
on and find the REALLY bad ones. I suppose if there's a
way (as has been previously requested) to suppress
warnings by adding comments - that would also solve
this - but it's not as attractive as being able to
customize the checks.
Log in to post a comment.