Skip to content
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
26 changes: 13 additions & 13 deletions dbus-java-core/src/main/java/org/freedesktop/dbus/Marshalling.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private static String[] recursiveGetDBusType(StringBuffer[] _out, Type _dataType
throw new DBusException(ERROR_MULTI_VALUED_ARRAY);
}
_out[_level].append(s[0]);
} else if (_dataType instanceof Class<?> && DBusSerializable.class.isAssignableFrom((Class<?>) _dataType)
} else if (_dataType instanceof Class<?> dtClazz && DBusSerializable.class.isAssignableFrom(dtClazz)
|| _dataType instanceof ParameterizedType pt
&& DBusSerializable.class.isAssignableFrom((Class<?>) pt.getRawType())) {
// it's a custom serializable type
Expand Down Expand Up @@ -395,12 +395,12 @@ public static int getJavaType(String _dbusType, List<Type> _resultValue, int _li
if (ArgumentType.DICT_ENTRY1 == _dbusType.charAt(idx + 1)) {
contained = new ArrayList<>();
int javaType = getJavaType(_dbusType.substring(idx + 2), contained, 2);
_resultValue.add(new DBusMapType(contained.get(0), contained.get(1)));
_resultValue.add(new DBusMapType(contained.getFirst(), contained.get(1)));
idx += javaType + 2;
} else {
contained = new ArrayList<>();
int javaType = getJavaType(_dbusType.substring(idx + 1), contained, 1);
_resultValue.add(new DBusListType(contained.get(0)));
_resultValue.add(new DBusListType(contained.getFirst()));
idx += javaType;
}
break;
Expand Down Expand Up @@ -452,7 +452,7 @@ public static int getJavaType(String _dbusType, List<Type> _resultValue, int _li
case ArgumentType.DICT_ENTRY1:
contained = new ArrayList<>();
int javaType = getJavaType(_dbusType.substring(idx + 1), contained, 2);
_resultValue.add(new DBusMapType(contained.get(0), contained.get(1)));
_resultValue.add(new DBusMapType(contained.getFirst(), contained.get(1)));
idx += javaType + 1;
break;
default:
Expand Down Expand Up @@ -577,33 +577,33 @@ static Object deSerializeParameter(Object _parameter, Type _type, AbstractConnec
}

// Turn a signature into a Type[]
if (_type instanceof Class && ((Class<?>) _type).isArray() && ((Class<?>) _type).getComponentType().equals(Type.class) && parameter instanceof String) {
if (_type instanceof Class<?> tClazz && tClazz.isArray() && tClazz.getComponentType().equals(Type.class) && parameter instanceof String str) {
List<Type> rv = new ArrayList<>();
getJavaType((String) parameter, rv, -1);
getJavaType(str, rv, -1);
parameter = rv.toArray(EMPTY_TYPE_ARRAY);
}

if (parameter instanceof DBusPath op) {
LOGGER.trace("Parameter is DBusPath");
if (_type instanceof Class && DBusInterface.class.isAssignableFrom((Class<?>) _type)) {
if (_type instanceof Class<?> tClazz && DBusInterface.class.isAssignableFrom(tClazz)) {
parameter = _conn.getExportedObject(op.getSource(), op.getPath(), (Class<DBusInterface>) _type);
} else {
parameter = new DBusPath(op.getPath());
}
}

// its an enum, parse either as the string name or the ordinal
if (parameter instanceof String str && _type instanceof Class && Enum.class.isAssignableFrom((Class<?>) _type)) {
if (parameter instanceof String str && _type instanceof Class<?> tClazz && Enum.class.isAssignableFrom(tClazz)) {
LOGGER.trace("Type seems to be an enum");
parameter = Enum.valueOf((Class<Enum>) _type, str);
}

// it should be a struct. create it
if (parameter instanceof Object[] objArr && _type instanceof Class && Struct.class.isAssignableFrom((Class<?>) _type)) {
if (parameter instanceof Object[] objArr && _type instanceof Class<?> tClazz && Struct.class.isAssignableFrom(tClazz)) {
LOGGER.trace("Creating Struct {} from {}", _type, parameter);
Type[] ts = Container.getTypeCache(_type);
if (ts == null) {
Field[] fs = ((Class<?>) _type).getDeclaredFields();
Field[] fs = tClazz.getDeclaredFields();
ts = new Type[fs.length];
for (Field f : fs) {
Position p = f.getAnnotation(Position.class);
Expand All @@ -617,7 +617,7 @@ static Object deSerializeParameter(Object _parameter, Type _type, AbstractConnec

// recurse over struct contents
parameter = deSerializeParameters(objArr, ts, _conn);
for (Constructor<?> con : ((Class<?>) _type).getDeclaredConstructors()) {
for (Constructor<?> con : tClazz.getDeclaredConstructors()) {
try {
LOGGER.trace("Trying to create instance of {} using constructor {} with parameters: {}", _type, con, objArr);
parameter = con.newInstance(objArr);
Expand Down Expand Up @@ -778,8 +778,8 @@ public static Object[] deSerializeParameters(Object[] _parameters, Type[] _types
continue;
}

if (types[i] instanceof Class
&& DBusSerializable.class.isAssignableFrom((Class<? extends Object>) types[i])
if (types[i] instanceof Class<? extends Object> tClazz
&& DBusSerializable.class.isAssignableFrom(tClazz)
|| types[i] instanceof ParameterizedType pt
&& DBusSerializable.class.isAssignableFrom((Class<? extends Object>) pt.getRawType())) {
Class<? extends DBusSerializable> dsc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ protected PropHandled handleGetAll(ExportedObject _exportObject, final MethodCal
} catch (Throwable _ex) {
getLogger().debug("Failed to invoke method call", _ex);
handleException(_methodCall,
new DBusExecutionException(String.format("Error Executing Method %s.%s: %s",
_methodCall.getInterface(), _methodCall.getName(), _ex.getMessage()), _ex));
new DBusExecutionException("Error Executing Method %s.%s: %s".formatted(
_methodCall.getInterface(), _methodCall.getName(), _ex.getMessage()), _ex));
}
});
return PropHandled.HANDLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public ReceivingServiceConfigBuilder<R> withMethodReturnThreadPriority(int _prio
/**
* Use virtual threads for the created signal thread(s).
* <p>
* Default: {@value false};
* Default: {@code false}
*
* @param _virtual true to use virtual threads, false to use native threads
* @return this
Expand All @@ -180,7 +180,7 @@ public ReceivingServiceConfigBuilder<R> withVirtualSignalThreads(boolean _virtua
/**
* Use virtual threads for the created error thread(s).
* <p>
* Default: {@value false};
* Default: {@code false}
*
* @param _virtual true to use virtual threads, false to use native threads
* @return this
Expand All @@ -195,7 +195,7 @@ public ReceivingServiceConfigBuilder<R> withVirtualErrorThreads(boolean _virtual
/**
* Use virtual threads for the created method call thread(s).
* <p>
* Default: {@value false};
* Default: {@code false}
*
* @param _virtual true to use virtual threads, false to use native threads
* @return this
Expand All @@ -210,7 +210,7 @@ public ReceivingServiceConfigBuilder<R> withMethodCallSignalThreads(boolean _vir
/**
* Use virtual threads for the created method return thread(s).
* <p>
* Default: {@value false};
* Default: {@code false}
*
* @param _virtual true to use virtual threads, false to use native threads
* @return this
Expand All @@ -225,7 +225,7 @@ public ReceivingServiceConfigBuilder<R> withVirtualMethodReturnThreads(boolean _
/**
* Use virtual threads for all created thread(s).
* <p>
* Default: {@value false};
* Default: {@code false}
*
* @param _virtual true to use virtual threads, false to use native threads
* @return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public <T extends DBusInterface> T dynamicProxy(String _source, String _path, Cl
}

RemoteObject ro = new RemoteObject(_source, _path, _type, false);
DBusInterface newi = (DBusInterface) Proxy.newProxyInstance(ifcs.get(0).getClassLoader(),
DBusInterface newi = (DBusInterface) Proxy.newProxyInstance(ifcs.getFirst().getClassLoader(),
ifcs.toArray(Class[]::new), new RemoteInvocationHandler(this, ro));
getImportedObjects().put(newi, ro);

Expand Down Expand Up @@ -302,7 +302,7 @@ public void requestBusName(String _busname) throws DBusException {
* @return unique name
*/
public String getUniqueName() {
return doWithBusNamesAndReturn(bn -> bn.get(0));
return doWithBusNamesAndReturn(bn -> bn.getFirst());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <T extends DBusInterface> T dynamicProxy(String _path, Class<T> _type) throws DB
}

RemoteObject ro = new RemoteObject(null, _path, _type, false);
DBusInterface newi = (DBusInterface) Proxy.newProxyInstance(ifcs.get(0).getClassLoader(), ifcs.toArray(EMPTY_CLASS_ARRAY), new RemoteInvocationHandler(this, ro));
DBusInterface newi = (DBusInterface) Proxy.newProxyInstance(ifcs.getFirst().getClassLoader(), ifcs.toArray(EMPTY_CLASS_ARRAY), new RemoteInvocationHandler(this, ro));
getImportedObjects().put(newi, ro);
return (T) newi;
} catch (Exception _ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if a message is denied due to a security policy
*/
public class AccessDenied extends DBusExecutionException {
@Serial
private static final long serialVersionUID = 368173196466740803L;

public AccessDenied(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if a arguments passed to the method are invalid
*/
public class InvalidMethodArgument extends DBusExecutionException {
@Serial
private static final long serialVersionUID = 2504012938615867394L;

public InvalidMethodArgument(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if the match rule is invalid
*/
public class MatchRuleInvalid extends DBusExecutionException {
@Serial
private static final long serialVersionUID = 6922529529288327323L;

public MatchRuleInvalid(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if there is no reply to a method call
*/
public class NoReply extends DBusExecutionException {
@Serial
private static final long serialVersionUID = 5280031560938871837L;

public NoReply(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if a called operation is not supported
*/
public class NotSupported extends DBusExecutionException {
@Serial
private static final long serialVersionUID = -3937521136197720266L;

public NotSupported(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if a attempt to edit read only property
*/
public class PropertyReadOnly extends DBusExecutionException {
@Serial
private static final long serialVersionUID = -8493757965292570003L;

public PropertyReadOnly(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if the requested service was not available
*/
public class ServiceUnknown extends DBusExecutionException {
@Serial
private static final long serialVersionUID = -8634413313381034023L;

public ServiceUnknown(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if a operation timed out
*/
public class Timeout extends DBusExecutionException {
@Serial
private static final long serialVersionUID = -1212844876312953745L;

public Timeout(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if a interface does not exist
*/
public class UnknownInterface extends DBusExecutionException {
@Serial
private static final long serialVersionUID = -6296696668185701195L;

public UnknownInterface(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if the method called was unknown on the remote object
*/
public class UnknownMethod extends DBusExecutionException {
@Serial
private static final long serialVersionUID = -6712037259368315246L;

public UnknownMethod(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if the object was unknown on a remote connection
*/
public class UnknownObject extends DBusExecutionException {
@Serial
private static final long serialVersionUID = 4951706443147828582L;

public UnknownObject(String _message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import org.freedesktop.dbus.exceptions.DBusExecutionException;

import java.io.Serial;

/**
* Thrown if a property does not exist in the interface
*/
public class UnknownProperty extends DBusExecutionException {
@Serial
private static final long serialVersionUID = 7993712944238574483L;

public UnknownProperty(String _message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.freedesktop.dbus.exceptions;

import java.io.Serial;

public class AddressResolvingException extends DBusExecutionException {

@Serial
private static final long serialVersionUID = -1636993356304776163L;

public AddressResolvingException(String _message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.freedesktop.dbus.exceptions;

import java.io.IOException;
import java.io.Serial;

public class AuthenticationException extends IOException {
@Serial
private static final long serialVersionUID = 1L;

public AuthenticationException(String _message, Throwable _cause) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.freedesktop.dbus.exceptions;

import java.io.Serial;

/**
* @since 5.1.1 - 2024-11-16
* @author hypfvieh
*/
public class ClassOutsideOfPackageException extends DBusException {
@Serial
private static final long serialVersionUID = 1L;

public ClassOutsideOfPackageException(Class<?> _clz) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.freedesktop.dbus.exceptions;

import java.io.Serial;

/**
* Thrown when something goes wrong with the connection to DBus.<p>
* This includes find the connection parameter (e.g. machine-id file) or establishing the connection.
Expand All @@ -8,6 +10,7 @@
* @since v3.3.0 - 2021-01-27
*/
public class DBusConnectionException extends DBusException {
@Serial
private static final long serialVersionUID = -1L;

public DBusConnectionException() {
Expand Down
Loading