Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A session of compile warning hunt #4472

Merged
merged 5 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public ExpiringCache(long expiry, Supplier<@Nullable V> action) {
* Returns the value - possibly from the cache, if it is still valid.
*/
public synchronized @Nullable V getValue() {
@Nullable
V cachedValue = value.get();
if (cachedValue == null || isExpired()) {
return refreshValue();
Expand Down Expand Up @@ -98,6 +99,7 @@ public final synchronized void invalidateValue() {
* @return the new value
*/
public synchronized @Nullable V refreshValue() {
@Nullable
V freshValue = action.get();
value = new SoftReference<>(freshValue);
expiresAt = calcExpiresAt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,11 @@ private void cleanCacheDirectory() throws IOException {
// 2 clean orphan (part of a pair (file + metadata) without a corresponding partner)
// 2-a delete a file without its metadata
for (Path path : filesInCacheFolder) {
if (path != null) {
String fileName = path.getFileName().toString();
// check corresponding metadata in storage
V metadata = storage.get(fileName);
if (metadata == null) {
Files.delete(path);
}
String fileName = path.getFileName().toString();
// check corresponding metadata in storage
V metadata = storage.get(fileName);
if (metadata == null) {
Files.delete(path);
}
}
// 2-b delete metadata without corresponding file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RunnableFuture;
Expand All @@ -43,7 +42,7 @@

/**
* A ScheduledExecutorService that will sequentially perform the tasks like a
* {@link Executors#newSingleThreadScheduledExecutor} backed by a thread pool.
* {@link java.util.concurrent.Executors#newSingleThreadScheduledExecutor} backed by a thread pool.
* This is a drop in replacement to a ScheduledExecutorService with one thread to avoid a lot of threads created, idling
* most of the time and wasting memory on low-end devices.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import static java.util.concurrent.Executors.defaultThreadFactory;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

Expand All @@ -25,10 +23,12 @@

/**
* A builder for {@link ThreadFactory} instances. This builder is intended to be used for creating thread factories to
* be used, e.g., when creating {@link Executor}s via the {@link Executors} utility methods.
* be used, e.g., when creating {@link java.util.concurrent.Executor}s via the {@link java.util.concurrent.Executors}
* utility methods.
* <p>
* The built {@link ThreadFactory} uses a wrapped {@link ThreadFactory} to create threads (defaulting to
* {@link Executors#defaultThreadFactory()}, and then overwrites thread properties as indicated in the build process.
* {@link java.util.concurrent.Executors#defaultThreadFactory()}, and then overwrites thread properties as indicated in
* the build process.
*
* @author Henning Sudbrock - Initial contribution
*/
Expand Down Expand Up @@ -60,7 +60,7 @@ private ThreadFactoryBuilder() {
/**
* Sets the wrapped thread factory used to create threads.
* <p>
* If set to null, {@link Executors#defaultThreadFactory()} is used.
* If set to null, {@link java.util.concurrent.Executors#defaultThreadFactory()} is used.
* <p>
* Defaults to null.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ protected void addProvider(Provider<E> provider) {
}
elementsAdded.forEach(this::notifyListenersAboutAddedElement);

if (provider instanceof ManagedProvider && providerClazz != null && readyService != null) {
readyService.markReady(
new ReadyMarker("managed", providerClazz.getSimpleName().replace("Provider", "").toLowerCase()));
if (provider instanceof ManagedProvider && providerClazz instanceof Class clazz
&& readyService instanceof ReadyService rs) {
rs.markReady(new ReadyMarker("managed", clazz.getSimpleName().replace("Provider", "").toLowerCase()));
}
logger.debug("Provider \"{}\" has been added.", provider.getClass().getName());
}
Expand Down Expand Up @@ -688,9 +688,9 @@ protected void unsetReadyService(ReadyService readyService) {
* @param event the event
*/
protected void postEvent(Event event) {
if (eventPublisher != null) {
if (eventPublisher instanceof EventPublisher ep) {
try {
eventPublisher.post(event);
ep.post(event);
} catch (RuntimeException ex) {
logger.error("Cannot post event of type \"{}\".", event.getType(), ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public String getPayload() {
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((payload == null) ? 0 : payload.hashCode());
result = prime * result + ((source == null) ? 0 : source.hashCode());
result = prime * result + ((topic == null) ? 0 : topic.hashCode());
result = prime * result + payload.hashCode();
result = prime * result + (source instanceof String local ? local.hashCode() : 0);
result = prime * result + topic.hashCode();
return result;
}

Expand All @@ -79,11 +79,7 @@ public boolean equals(@Nullable Object obj) {
return false;
}
AbstractEvent other = (AbstractEvent) obj;
if (payload == null) {
if (other.payload != null) {
return false;
}
} else if (!payload.equals(other.payload)) {
if (!payload.equals(other.payload)) {
return false;
}
if (source == null) {
Expand All @@ -93,11 +89,7 @@ public boolean equals(@Nullable Object obj) {
} else if (!source.equals(other.source)) {
return false;
}
if (topic == null) {
if (other.topic != null) {
return false;
}
} else if (!topic.equals(other.topic)) {
if (!topic.equals(other.topic)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.openhab.core.events.AbstractEventFactory;
import org.openhab.core.events.Event;
import org.openhab.core.events.EventFactory;
import org.openhab.core.types.Type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When removing it here, you probably need to fully qualify it in the Javadoc (e.g. line 40).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import org.osgi.service.component.annotations.Component;

/**
Expand All @@ -38,7 +37,7 @@ public SystemEventFactory() {
}

/**
* Creates a trigger event from a {@link Type}.
* Creates a trigger event from a {@link org.openhab.core.types.Type}.
*
* @param startlevel Startlevel of system
* @return Created start level event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + key.hashCode();
result = prime * result + ((locale != null) ? locale.hashCode() : 0);
result = prime * result + (locale instanceof String string ? string.hashCode() : 0);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public Authentication authenticate(Credentials credentials) throws Authenticatio
unmatched = false;
try {
Authentication authentication = provider.authenticate(credentials);
if (authentication != null) {
return authentication;
}
return authentication;
} catch (AuthenticationException e) {
logger.info("Failed to authenticate credentials {} with provider {}", credentials.getClass(),
provider, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
package org.openhab.core.internal.auth;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.auth.ManagedUser;
import org.openhab.core.auth.User;
import org.openhab.core.common.registry.DefaultAbstractManagedProvider;
import org.openhab.core.common.registry.ManagedProvider;
import org.openhab.core.storage.StorageService;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* A {@link ManagedProvider} for {@link ManagedUser} entities
* A {@link org.openhab.core.common.registry.ManagedProvider} for {@link org.openhab.core.auth.ManagedUser} entities
*
* @author Yannick Schaus - initial contribution
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ void handleTimeout(Method method, Invocation invocation) {
} else {
logger.debug(MSG_TIMEOUT_Q, timeout, toString(invocation.getInvocationStack()));
}
if (timeoutHandler != null) {
timeoutHandler.run();
if (timeoutHandler instanceof Runnable handler) {
handler.run();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

import org.openhab.core.events.Event;
import org.openhab.core.events.EventFactory;
import org.openhab.core.events.EventSubscriber;
import org.osgi.service.component.ComponentContext;
Expand All @@ -33,8 +32,8 @@
* The {@link OSGiEventManager} provides an OSGi based default implementation of the openHAB event bus.
*
* The OSGiEventHandler tracks {@link EventSubscriber}s and {@link EventFactory}s, receives OSGi events (by
* implementing the OSGi {@link EventHandler} interface) and dispatches the received OSGi events as OH {@link Event}s
* to the {@link EventSubscriber}s if the provided filter applies.
* implementing the OSGi {@link EventHandler} interface) and dispatches the received OSGi events
* as OH {@link org.openhab.core.events.Event}s to the {@link EventSubscriber}s if the provided filter applies.
*
* @author Stefan Bußweiler - Initial contribution
* @author Markus Rathgeb - Return on received events as fast as possible (handle event in another thread)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;

import javax.measure.Quantity;
Expand Down Expand Up @@ -100,7 +99,8 @@
* and {@link LocationProvider} service interfaces.
*
* <p>
* This implementation uses the i18n mechanism of Java ({@link ResourceBundle}) to translate a given key into text. The
* This implementation uses the i18n mechanism of Java ({@link java.util.ResourceBundle}) to translate a
* given key into text. The
* resources must be placed under the specific directory {@link LanguageResourceBundleManager#RESOURCE_DIRECTORY} within
* the certain modules. Each module is tracked in the platform by using the {@link ResourceBundleTracker} and managed by
* using one certain {@link LanguageResourceBundleManager} which is responsible for the translation.
Expand Down Expand Up @@ -134,7 +134,6 @@ public class I18nProviderImpl
public static final String REGION = "region";
public static final String VARIANT = "variant";
private @Nullable Locale locale;
private @Nullable String currencyCode;

// TranslationProvider
private final ResourceBundleTracker resourceBundleTracker;
Expand Down Expand Up @@ -301,7 +300,7 @@ private void setTimeZone(final @Nullable String zoneId) {

if (oldTimeZone != null && this.timeZone == null) {
logger.info("Time zone is not set, falling back to the default time zone.");
} else if (this.timeZone != null && !this.timeZone.equals(oldTimeZone)) {
} else if (this.timeZone instanceof ZoneId zId && !zId.equals(oldTimeZone)) {
logger.info("Time zone set to '{}'.", this.timeZone);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ private String getTranslatedText(String resourceName, String key, Locale locale)
ResourceBundle resourceBundle = ResourceBundle.getBundle(resourceName, locale, this.resourceClassLoader,
Control.getNoFallbackControl(Control.FORMAT_PROPERTIES));

if (resourceBundle != null) {
return resourceBundle.getString(key);
}
return resourceBundle.getString(key);
} catch (Exception ex) {
// nothing to do
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
import org.openhab.core.items.ItemBuilder;
import org.openhab.core.items.ItemBuilderFactory;
import org.openhab.core.items.ItemFactory;
import org.openhab.core.library.CoreItemFactory;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;

/**
* Provides an {@link ItemBuilder} with all available {@link ItemFactory}s set. The {@link CoreItemFactory} will always
* be present.
* Provides an {@link ItemBuilder} with all available {@link ItemFactory}s set.
* The {@link org.openhab.core.library.CoreItemFactory} will always be present.
*
* @author Henning Treu - Initial contribution
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,28 +156,24 @@ public Collection<Item> getItems(String pattern) {

private void addToGroupItems(Item item, List<String> groupItemNames) {
for (String groupName : groupItemNames) {
if (groupName != null) {
try {
if (getItem(groupName) instanceof GroupItem groupItem) {
groupItem.addMember(item);
}
} catch (ItemNotFoundException e) {
// the group might not yet be registered, let's ignore this
try {
if (getItem(groupName) instanceof GroupItem groupItem) {
groupItem.addMember(item);
}
} catch (ItemNotFoundException e) {
// the group might not yet be registered, let's ignore this
}
}
}

private void replaceInGroupItems(Item oldItem, Item newItem, List<String> groupItemNames) {
for (String groupName : groupItemNames) {
if (groupName != null) {
try {
if (getItem(groupName) instanceof GroupItem groupItem) {
groupItem.replaceMember(oldItem, newItem);
}
} catch (ItemNotFoundException e) {
// the group might not yet be registered, let's ignore this
try {
if (getItem(groupName) instanceof GroupItem groupItem) {
groupItem.replaceMember(oldItem, newItem);
}
} catch (ItemNotFoundException e) {
// the group might not yet be registered, let's ignore this
}
}
}
Expand Down Expand Up @@ -229,14 +225,12 @@ private void addMembersToGroupItem(GroupItem groupItem) {

private void removeFromGroupItems(Item item, List<String> groupItemNames) {
for (String groupName : groupItemNames) {
if (groupName != null) {
try {
if (getItem(groupName) instanceof GroupItem groupItem) {
groupItem.removeMember(item);
}
} catch (ItemNotFoundException e) {
// the group might not yet be registered, let's ignore this
try {
if (getItem(groupName) instanceof GroupItem groupItem) {
groupItem.removeMember(item);
}
} catch (ItemNotFoundException e) {
// the group might not yet be registered, let's ignore this
}
}
}
Expand Down
Loading