Skip to content

Commit

Permalink
IGNITE-19510 Remove deprecated public API exception constructors (#5008)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptupitsyn authored Jan 8, 2025
1 parent d224f6f commit 3739f46
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.apache.ignite.lang.ErrorGroup.ERR_PREFIX;
import static org.apache.ignite.lang.ErrorGroup.errorMessage;
import static org.apache.ignite.lang.ErrorGroup.extractErrorCode;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
import static org.apache.ignite.lang.ErrorGroups.errorGroupByCode;
import static org.apache.ignite.lang.ErrorGroups.extractGroupCode;
import static org.apache.ignite.lang.util.TraceIdUtils.getOrCreateTraceId;
Expand Down Expand Up @@ -57,45 +56,6 @@ public class IgniteException extends RuntimeException implements TraceableExcept
@SuppressWarnings({"NonFinalFieldOfException", "FieldMayBeFinal"})
private UUID traceId;

/**
* Creates an empty exception.
*/
@Deprecated
public IgniteException() {
this(INTERNAL_ERR);
}

/**
* Creates an exception with the given error message.
*
* @param msg Error message.
*/
@Deprecated
public IgniteException(String msg) {
this(INTERNAL_ERR, msg);
}

/**
* Creates a grid exception with the given throwable as a cause and source of the error message.
*
* @param cause Non-null throwable cause.
*/
@Deprecated
public IgniteException(Throwable cause) {
this(INTERNAL_ERR, cause);
}

/**
* Creates an exception with the given error message and optional nested exception.
*
* @param msg Error message.
* @param cause Optional nested exception (can be {@code null}).
*/
@Deprecated
public IgniteException(String msg, @Nullable Throwable cause) {
this(INTERNAL_ERR, msg, cause);
}

/**
* Creates an exception with the given error code.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.ignite.lang;

import java.util.UUID;
import org.apache.ignite.lang.ErrorGroups.Common;
import org.apache.ignite.lang.ErrorGroups.Marshalling;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -33,7 +33,7 @@ public class MarshallerException extends IgniteException {
* @param cause Non-null throwable cause.
*/
public MarshallerException(String msg, @Nullable Throwable cause) {
super(Common.USER_OBJECT_SERIALIZATION_ERR, msg, cause);
super(Marshalling.COMMON_ERR, msg, cause);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,6 @@

/** This exception is thrown if a transaction can't be finished for some reason. */
public class TransactionException extends IgniteException {
/**
* Creates a new transaction exception with a message.
*
* @param message The message.
*/
@Deprecated
public TransactionException(String message) {
super(message);
}

/**
* Creates a new transaction exception with a cause.
*
* @param cause The cause.
*/
@Deprecated
public TransactionException(Throwable cause) {
super(cause);
}

/**
* Creates a new transaction exception with the given error code and cause.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.ignite.client.handler;

import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import org.apache.ignite.lang.IgniteException;
import org.jetbrains.annotations.Nullable;

Expand All @@ -43,7 +45,9 @@ public ClientResource(Object obj, @Nullable Runnable releaseRunnable) {
*/
public <T> T get(Class<T> type) {
if (!type.isInstance(obj)) {
throw new IgniteException("Incorrect resource type. Expected " + type.getName() + ", but got " + obj.getClass().getName());
throw new IgniteException(
INTERNAL_ERR,
"Incorrect resource type. Expected " + type.getName() + ", but got " + obj.getClass().getName());
}

return (T) obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.Serializable;
import java.net.Inet6Address;
import java.net.UnknownHostException;
import org.apache.ignite.lang.ErrorGroups.Client;
import org.apache.ignite.lang.IgniteException;

/**
Expand Down Expand Up @@ -107,7 +108,7 @@ public static HostAndPort parse(String addrStr, int dfltPort, String errMsgPrefi
* @return Parsed port.
* @throws IgniteException If failed.
*/
private static int parsePort(String portStr, String addrStr, String errMsgPrefix) throws IgniteException {
private static int parsePort(String portStr, String addrStr, String errMsgPrefix) {
try {
int port = Integer.parseInt(portStr);

Expand All @@ -129,8 +130,8 @@ private static int parsePort(String portStr, String addrStr, String errMsgPrefix
* @param errMsg Error message.
* @return Exception.
*/
private static IgniteException createParseError(String addrStr, String errMsgPrefix, String errMsg) {
return new IgniteException(errMsgPrefix + " (" + errMsg + "): " + addrStr);
private static RuntimeException createParseError(String addrStr, String errMsgPrefix, String errMsg) {
return new IgniteException(Client.CONFIGURATION_ERR, errMsgPrefix + " (" + errMsg + "): " + addrStr);
}

/**
Expand All @@ -142,8 +143,8 @@ private static IgniteException createParseError(String addrStr, String errMsgPre
* @param cause Cause exception.
* @return Exception.
*/
private static IgniteException createParseError(String addrStr, String errMsgPrefix, String errMsg, Throwable cause) {
return new IgniteException(errMsgPrefix + " (" + errMsg + "): " + addrStr, cause);
private static RuntimeException createParseError(String addrStr, String errMsgPrefix, String errMsg, Throwable cause) {
return new IgniteException(Client.CONFIGURATION_ERR, errMsgPrefix + " (" + errMsg + "): " + addrStr, cause);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static java.util.concurrent.CompletableFuture.failedFuture;
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
Expand Down Expand Up @@ -153,13 +154,13 @@ public TestClientHandlerModule(
@Override
public CompletableFuture<Void> startAsync(ComponentContext componentContext) {
if (channel != null) {
throw new IgniteException("ClientHandlerModule is already started.");
throw new IgniteException(INTERNAL_ERR, "ClientHandlerModule is already started.");
}

try {
channel = startEndpoint().channel();
} catch (InterruptedException e) {
throw new IgniteException(e);
throw new IgniteException(INTERNAL_ERR, e);
}

return nullCompletedFuture();
Expand Down Expand Up @@ -250,13 +251,13 @@ protected void initChannel(Channel ch) {
if (bindRes.isSuccess()) {
ch = bindRes.channel();
} else if (!(bindRes.cause() instanceof BindException)) {
throw new IgniteException(bindRes.cause());
throw new IgniteException(INTERNAL_ERR, bindRes.cause());
}

if (ch == null) {
String msg = "Cannot start thin client connector endpoint. Port " + port + " is in use.";

throw new IgniteException(msg);
throw new IgniteException(INTERNAL_ERR, msg);
}

return ch.closeFuture();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.client.fakes;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;
import static org.mockito.Mockito.mock;

import java.util.ArrayList;
Expand Down Expand Up @@ -106,7 +107,7 @@ public TableViewInternal createTable(String name, int id) {
var oldTable = tables.putIfAbsent(name, newTable);

if (oldTable != null) {
throw new IgniteException(TABLE_EXISTS);
throw new IgniteException(INTERNAL_ERR, TABLE_EXISTS);
}

tablesById.put(newTable.tableId(), newTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.ignite.internal.configuration.presentation;

import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigFactory;
Expand Down Expand Up @@ -89,7 +91,7 @@ public CompletableFuture<Void> update(String cfgUpdate) {
} else if (e instanceof ConfigurationChangeException) {
throw (RuntimeException) e.getCause();
} else {
throw new IgniteException(e);
throw new IgniteException(INTERNAL_ERR, e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.UUID;
import org.apache.ignite.lang.IgniteException;

/**
* Binary writer.
Expand Down Expand Up @@ -145,98 +144,4 @@ public interface MarshallerWriter {
* @param val Value.
*/
void writeDateTime(LocalDateTime val);

/**
* Writes an object value.
*
* @param col Column.
* @param val Value.
*/
default void writeValue(MarshallerColumn col, Object val) {
if (val == null) {
writeNull();

return;
}

switch (col.type()) {
case BOOLEAN: {
writeBoolean((boolean) val);

break;
}
case BYTE: {
writeByte((byte) val);

break;
}
case SHORT: {
writeShort((short) val);

break;
}
case INT: {
writeInt((int) val);

break;
}
case LONG: {
writeLong((long) val);

break;
}
case FLOAT: {
writeFloat((float) val);

break;
}
case DOUBLE: {
writeDouble((double) val);

break;
}
case UUID: {
writeUuid((UUID) val);

break;
}
case TIME: {
writeTime((LocalTime) val);

break;
}
case DATE: {
writeDate((LocalDate) val);

break;
}
case DATETIME: {
writeDateTime((LocalDateTime) val);

break;
}
case TIMESTAMP: {
writeTimestamp((Instant) val);

break;
}
case STRING: {
writeString((String) val);

break;
}
case BYTE_ARR: {
writeBytes((byte[]) val);

break;
}
case DECIMAL: {
writeBigDecimal((BigDecimal) val, col.scale());

break;
}
default:
throw new IgniteException("Unexpected value: " + col.type());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.apache.ignite.internal.util.IgniteUtils.closeAll;
import static org.apache.ignite.internal.util.IgniteUtils.safeAbs;
import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
Expand Down Expand Up @@ -349,7 +350,7 @@ private CompletableFuture<Void> sendViaNetwork(
try {
descriptors = prepareMarshal(message);
} catch (Exception e) {
return failedFuture(new IgniteException("Failed to marshal message: " + e.getMessage(), e));
return failedFuture(new IgniteException(INTERNAL_ERR, "Failed to marshal message: " + e.getMessage(), e));
}

return connectionManager.channel(consistentId, type, addr)
Expand Down Expand Up @@ -479,7 +480,7 @@ private void unmarshalMessage(InNetworkObject obj) {
try {
obj.message().unmarshal(marshaller, obj.registry());
} catch (Exception e) {
throw new IgniteException("Failed to unmarshal message: " + e.getMessage(), e);
throw new IgniteException(INTERNAL_ERR, "Failed to unmarshal message: " + e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.apache.ignite.internal.network.serialization.Classes.hasWriteReplace;
import static org.apache.ignite.internal.network.serialization.Classes.isExternalizable;
import static org.apache.ignite.internal.network.serialization.Classes.isSerializable;
import static org.apache.ignite.lang.ErrorGroups.Common.INTERNAL_ERR;

import java.io.Externalizable;
import java.io.ObjectInputStream;
Expand Down Expand Up @@ -213,7 +214,7 @@ private static void checkHasPublicNoArgConstructor(Class<? extends Externalizabl
}

if (!hasPublicNoArgConstructor) {
throw new IgniteException(
throw new IgniteException(INTERNAL_ERR,
"Externalizable class " + clazz.getName() + " has no public no-arg constructor");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

package org.apache.ignite.internal.network.serialization.marshal;

import org.apache.ignite.lang.ErrorGroups.Common;
import org.apache.ignite.lang.IgniteException;

/**
* Thrown to indicate that an object cannot be marshalled, or that it will be impossible to unmarshal it then.
*/
class MarshallingNotSupportedException extends IgniteException {
public MarshallingNotSupportedException(String msg) {
super(msg);
super(Common.USER_OBJECT_SERIALIZATION_ERR, msg);
}
}
Loading

0 comments on commit 3739f46

Please sign in to comment.