Fix some recently introduced SAT and NPE issues (#3251)
Signed-off-by: Wouter Born <github@maindrain.net>pull/3256/head
parent
687688db7e
commit
7888da1684
|
@ -59,7 +59,7 @@ public class ToneSynthesizer {
|
|||
* You can optionally add the character "'" to increase the note one octave.
|
||||
* You can optionally add ":ms" where ms is an int value to customize the note/silence milliseconds duration
|
||||
* (defaults to 200ms).
|
||||
*
|
||||
*
|
||||
* @param melody to be parsed.
|
||||
* @return list of {@link Tone} instances.
|
||||
* @throws ParseException if melody can not be played.
|
||||
|
@ -87,7 +87,7 @@ public class ToneSynthesizer {
|
|||
if (noteObj.isPresent()) {
|
||||
melodySounds.add(noteTone(noteObj.get(), soundMillis, octaves));
|
||||
break;
|
||||
} else if (note.equals("O") || note.equals("0")) {
|
||||
} else if ("O".equals(note) || "0".equals(note)) {
|
||||
melodySounds.add(silenceTone(soundMillis));
|
||||
break;
|
||||
}
|
||||
|
@ -127,21 +127,20 @@ public class ToneSynthesizer {
|
|||
|
||||
/**
|
||||
* Synthesize a list of {@link Tone} into a wav audio stream
|
||||
*
|
||||
*
|
||||
* @param tones the list of {@link Tone}
|
||||
* @return an audio stream with the synthesized tones
|
||||
* @throws IOException in case of problems writing the audio stream
|
||||
*/
|
||||
public AudioStream getStream(List<Tone> tones) throws IOException {
|
||||
int byteRate = (int) (sampleRate * bitDepth * channels / 8);
|
||||
byte[] audioBuffer = new byte[0];
|
||||
byte[] audioBuffer = {};
|
||||
var fixedTones = new ArrayList<>(tones);
|
||||
fixedTones.add(silenceTone(100));
|
||||
for (var sound : fixedTones) {
|
||||
var frequency = sound.frequency;
|
||||
var millis = sound.millis;
|
||||
int samplesPerChannel = (int) Math.ceil(sampleRate * (((double) millis) / 1000));
|
||||
int byteSize = (int) Math.ceil(byteRate * ((double) millis / 1000));
|
||||
byte[] audioPart = getAudioBytes(frequency, samplesPerChannel);
|
||||
audioBuffer = ByteBuffer.allocate(audioBuffer.length + audioPart.length).put(audioBuffer).put(audioPart)
|
||||
.array();
|
||||
|
@ -193,10 +192,10 @@ public class ToneSynthesizer {
|
|||
audioBuffer.putShort(sample);
|
||||
break;
|
||||
case 24:
|
||||
putInt24Bits(audioBuffer, ((int) sample) << 8);
|
||||
putInt24Bits(audioBuffer, (sample) << 8);
|
||||
break;
|
||||
case 32:
|
||||
audioBuffer.putInt(((int) sample) << 16);
|
||||
audioBuffer.putInt((sample) << 16);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@ import org.openhab.core.audio.AudioManager;
|
|||
import org.openhab.core.automation.Action;
|
||||
import org.openhab.core.automation.handler.BaseActionModuleHandler;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* This is an ModuleHandler implementation for Actions that synthesize a tone melody.
|
||||
|
@ -37,8 +35,6 @@ public class SynthesizeActionHandler extends BaseActionModuleHandler {
|
|||
public static final String PARAM_SINK = "sink";
|
||||
public static final String PARAM_VOLUME = "volume";
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(SynthesizeActionHandler.class);
|
||||
|
||||
private final AudioManager audioManager;
|
||||
private final String melody;
|
||||
private final @Nullable String sink;
|
||||
|
|
|
@ -17,8 +17,6 @@ import java.util.function.Consumer;
|
|||
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.automation.RuleManager;
|
||||
import org.openhab.core.automation.RuleRegistry;
|
||||
import org.openhab.core.automation.module.script.action.ScriptExecution;
|
||||
import org.openhab.core.automation.module.script.action.Timer;
|
||||
import org.openhab.core.scheduler.Scheduler;
|
||||
|
@ -37,15 +35,10 @@ import org.osgi.service.component.annotations.Reference;
|
|||
public class ScriptExecutionImpl implements ScriptExecution {
|
||||
|
||||
private final Scheduler scheduler;
|
||||
private final RuleManager ruleManager;
|
||||
private final RuleRegistry ruleRegistry;
|
||||
|
||||
@Activate
|
||||
public ScriptExecutionImpl(@Reference RuleRegistry ruleRegistry, @Reference RuleManager ruleManager,
|
||||
@Reference Scheduler scheduler) {
|
||||
this.ruleRegistry = ruleRegistry;
|
||||
public ScriptExecutionImpl(@Reference Scheduler scheduler) {
|
||||
this.scheduler = scheduler;
|
||||
this.ruleManager = ruleManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -62,16 +62,19 @@ public class CompleterWrapper implements Completer {
|
|||
|
||||
if (commandLine.getArguments().length > 1) {
|
||||
String arg = commandLine.getArguments()[0];
|
||||
if (!arg.equals(command) && !arg.equals(localGlobalCommand))
|
||||
if (!arg.equals(command) && !arg.equals(localGlobalCommand)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (commandLine.getCursorArgumentIndex() < 0)
|
||||
if (commandLine.getCursorArgumentIndex() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
var localCompleter = completer;
|
||||
if (localCompleter == null)
|
||||
if (localCompleter == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
String[] args = commandLine.getArguments();
|
||||
boolean result = localCompleter.complete(Arrays.copyOfRange(args, 1, args.length),
|
||||
|
@ -86,12 +89,14 @@ public class CompleterWrapper implements Completer {
|
|||
String arg = commandLine.getArguments()[0];
|
||||
arg = arg.substring(0, commandLine.getArgumentPosition());
|
||||
|
||||
if (command.startsWith(arg))
|
||||
if (command.startsWith(arg)) {
|
||||
candidates.add(new Candidate(command, command, null, commandDescription, null, null, true));
|
||||
}
|
||||
String localGlobalCommand = globalCommand;
|
||||
if (localGlobalCommand != null && localGlobalCommand.startsWith(arg))
|
||||
if (localGlobalCommand != null && localGlobalCommand.startsWith(arg)) {
|
||||
candidates.add(new Candidate(localGlobalCommand, localGlobalCommand, null, commandDescription, null,
|
||||
null, true));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,9 +13,7 @@
|
|||
package org.openhab.core.io.rest.auth.internal;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
@ -48,16 +46,16 @@ public class AuthFilterTest {
|
|||
@InjectMocks
|
||||
private @NonNullByDefault({}) AuthFilter authFilter;
|
||||
|
||||
private @Mock @NonNullByDefault({}) JwtHelper jwtHelperMock;
|
||||
private @Mock @NonNullByDefault({}) UserRegistry userRegistryMock;
|
||||
// These mocks are inject into authFilter during setup
|
||||
public @Mock @NonNullByDefault({}) JwtHelper jwtHelperMock;
|
||||
public @Mock @NonNullByDefault({}) UserRegistry userRegistryMock;
|
||||
|
||||
private @Mock @NonNullByDefault({}) ContainerRequestContext containerRequestContext;
|
||||
|
||||
private @Mock @NonNullByDefault({}) HttpServletRequest servletRequest;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
MockitoAnnotations.openMocks(this);
|
||||
when(servletRequest.getRemoteAddr()).thenReturn("192.168.0.100");
|
||||
}
|
||||
|
||||
|
|
|
@ -53,10 +53,12 @@ public class EventDTO {
|
|||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
EventDTO eventDTO = (EventDTO) o;
|
||||
return Objects.equals(type, eventDTO.type) && Objects.equals(topic, eventDTO.topic)
|
||||
&& Objects.equals(payload, eventDTO.payload) && Objects.equals(source, eventDTO.source)
|
||||
|
|
|
@ -179,7 +179,8 @@ public class EventWebSocket {
|
|||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
String message = error == null ? "<null>" : error.getMessage();
|
||||
|
||||
String message = error == null ? "<null>" : Objects.requireNonNullElse(error.getMessage(), "<null>");
|
||||
logger.info("WebSocket error: {}", message);
|
||||
onClose(StatusCode.NO_CODE, message);
|
||||
}
|
||||
|
|
|
@ -82,12 +82,12 @@ public class ThingStatusInfoEvent extends AbstractEvent {
|
|||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o)
|
||||
if (this == o) {
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
}
|
||||
if (o == null || getClass() != o.getClass() || !super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
ThingStatusInfoEvent that = (ThingStatusInfoEvent) o;
|
||||
return thingUID.equals(that.thingUID) && thingStatusInfo.equals(that.thingStatusInfo);
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
*/
|
||||
package org.openhab.core.library.items;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
@ -147,13 +146,13 @@ public class NumberItemTest {
|
|||
item.setEventPublisher(eventPublisher);
|
||||
|
||||
QuantityType<?> command = new QuantityType<>("15 °C");
|
||||
item.send(new QuantityType<>("15 °C"));
|
||||
item.send(command);
|
||||
|
||||
ArgumentCaptor<ItemCommandEvent> captor = ArgumentCaptor.forClass(ItemCommandEvent.class);
|
||||
verify(eventPublisher).post(captor.capture());
|
||||
|
||||
ItemCommandEvent event = captor.getValue();
|
||||
assertThat(event.getItemCommand(), is(new QuantityType<>("15 °C")));
|
||||
assertThat(event.getItemCommand(), is(command));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -957,7 +957,6 @@ public class InboxOSGiTest extends JavaOSGiTest {
|
|||
@Test
|
||||
@SuppressWarnings("null")
|
||||
public void assertThatApproveSetsTheDiscoveredLabelIfNoOtherIsGiven() {
|
||||
|
||||
inbox.add(testDiscoveryResult);
|
||||
Thing approvedThing = inbox.approve(testThing.getUID(), null, null);
|
||||
Thing addedThing = registry.get(testThing.getUID());
|
||||
|
|
|
@ -13,10 +13,7 @@
|
|||
package org.openhab.core.thing.link;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
|
@ -54,9 +51,9 @@ public class ItemChannelLinkOSGiTest extends JavaOSGiTest {
|
|||
|
||||
private static final String BULK_BASE_THING_UID = "binding:type:thing";
|
||||
private static final String BULK_BASE_ITEM_NAME = "item";
|
||||
private static int BULK_ITEM_COUNT = 3;
|
||||
private static int BULK_THING_COUNT = 3;
|
||||
private static int BULK_CHANNEL_COUNT = 3;
|
||||
private static final int BULK_ITEM_COUNT = 3;
|
||||
private static final int BULK_THING_COUNT = 3;
|
||||
private static final int BULK_CHANNEL_COUNT = 3;
|
||||
|
||||
private static final String ITEM = "item";
|
||||
private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID("binding:thing");
|
||||
|
|
Loading…
Reference in New Issue