Ignore:
Timestamp:
2016-12-14T15:50:53+01:00 (7 years ago)
Author:
Don-vip
Message:

sonar - squid:S2259 - Null pointers should not be dereferenced

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java

    r11100 r11397  
    124124     */
    125125    public static void play(URL url) throws Exception {
    126         AudioPlayer.getInstance().command.play(url, 0.0, 1.0);
     126        AudioPlayer instance = AudioPlayer.getInstance();
     127        if (instance != null)
     128            instance.command.play(url, 0.0, 1.0);
    127129    }
    128130
     
    134136     */
    135137    public static void play(URL url, double seconds) throws Exception {
    136         AudioPlayer.getInstance().command.play(url, seconds, 1.0);
     138        AudioPlayer instance = AudioPlayer.getInstance();
     139        if (instance != null)
     140            instance.command.play(url, seconds, 1.0);
    137141    }
    138142
     
    145149     */
    146150    public static void play(URL url, double seconds, double speed) throws Exception {
    147         AudioPlayer.getInstance().command.play(url, seconds, speed);
     151        AudioPlayer instance = AudioPlayer.getInstance();
     152        if (instance != null)
     153            instance.command.play(url, seconds, speed);
    148154    }
    149155
     
    153159     */
    154160    public static void pause() throws Exception {
    155         AudioPlayer.getInstance().command.pause();
     161        AudioPlayer instance = AudioPlayer.getInstance();
     162        if (instance != null)
     163            instance.command.pause();
    156164    }
    157165
     
    161169     */
    162170    public static URL url() {
    163         return AudioPlayer.getInstance().playingUrl;
     171        AudioPlayer instance = AudioPlayer.getInstance();
     172        return instance == null ? null : instance.playingUrl;
    164173    }
    165174
     
    169178     */
    170179    public static boolean paused() {
    171         return AudioPlayer.getInstance().state == State.PAUSED;
     180        AudioPlayer instance = AudioPlayer.getInstance();
     181        return instance == null ? false : (instance.state == State.PAUSED);
    172182    }
    173183
     
    177187     */
    178188    public static boolean playing() {
    179         return AudioPlayer.getInstance().state == State.PLAYING;
     189        AudioPlayer instance = AudioPlayer.getInstance();
     190        return instance == null ? false : (instance.state == State.PLAYING);
    180191    }
    181192
     
    185196     */
    186197    public static double position() {
    187         return AudioPlayer.getInstance().position;
     198        AudioPlayer instance = AudioPlayer.getInstance();
     199        return instance == null ? -1 : instance.position;
    188200    }
    189201
     
    193205     */
    194206    public static double speed() {
    195         return AudioPlayer.getInstance().speed;
     207        AudioPlayer instance = AudioPlayer.getInstance();
     208        return instance == null ? -1 : instance.speed;
    196209    }
    197210
Note: See TracChangeset for help on using the changeset viewer.