Skip to content

SunPhase is not thread safe #14

@NaanProphet

Description

@NaanProphet

Because of the setters on private Calendar startDate, endDate; the SunPhase class is not thread safe. And since com.florianmski.suncalc.SunCalc which calls the setters is in a different package from com.florianmski.suncalc.models.SunPhase, the setter can't even be made package private for better encapsulation.

Perhaps we SunPhase should only house the the existing constructor's final variables:

    private final Name name;
    private final double startAngle, endAngle;
    private final boolean startRise, endRise;

and then, once the date is known, we construct and return a new SunPhaseDay class once the date is specified in SunCalc#getPhases that includes:

    private final Name name;
    private final double startAngle, endAngle;
    private final boolean startRise, endRise;
    private final Calendar startDate, endDate;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions