Name shadowing and compiler warnings

A small thing, but worth watching out for as a possible source of insidious bugs that are hard to spot.

Example:

public NJTree(SequenceI[] sequence, AlignmentView seqData, String type, String pwtype, ScoreModelI sm, int start, int end)

{

this.type = type;

if (!(type.equals(“NJ”)))

{

type = “AV”;

}

The code at the end has no effect - it updates the parameter variable (too late), not the field of the same name.

It seems not to matter here, as the third possible type value of “FromFile” doesn’t reach this method (I think!).

Enabling compiler warnings for ‘parameter hides field’, and clearing the warnings by changing the parameter name, can avoid this.

I had this warning turned on but not for constructors - will change that in the shared Eclipse config file next time I am on develop.

mungo

The University of Dundee is a registered Scottish Charity, No: SC015096

···

Email signature

University of Dundee shield logo

Mungo Carstairs
Jalview Computational Scientist

The Barton Group
Division of Computational Biology

School of Life Sciences

University of Dundee, Dundee, Scotland, UK

www.jalview.org

www.compbio.dundee.ac.uk
g.m.carstairs@dundee.ac.uk

University of Dundee FacebookUniversity of Dundee TwitterUniversity of Dundee LinkedInUniversity of Dundee YouTubeUniversity of Dundee InstagramUniversity of Dundee Snapchat
We’re Scottish University of the Year again!
The Times / Sunday Times Good University Guide 2016 and 2017

Well spotted! We need to tall about the ‘fromFile’ type…

···

Email signature

University of Dundee shield logo

Mungo Carstairs
Jalview Computational Scientist

The Barton Group
Division of Computational Biology

School of Life Sciences

University of Dundee, Dundee, Scotland, UK

www.jalview.org

www.compbio.dundee.ac.uk
g.m.carstairs@dundee.ac.uk

University of Dundee FacebookUniversity of Dundee TwitterUniversity of Dundee LinkedInUniversity of Dundee YouTubeUniversity of Dundee InstagramUniversity of Dundee Snapchat
We’re Scottish University of the Year again!
The Times / Sunday Times Good University Guide 2016 and 2017