From e877eac7bba341c6d050b10fd5666d609a9ea19d Mon Sep 17 00:00:00 2001 From: yueh Date: Wed, 9 Dec 2015 18:44:07 +0100 Subject: [PATCH] Fixes #2044: No longer uses internal exceptions Added 3 new exception as subclass to FailedConnection to allow a more precise handling and/or logging. --- .../ExistingConnectionException.java | 56 +++++++++++++++++++ .../api/exceptions/FailedConnection.java | 21 +++++++ .../NullNodeConnectionException.java | 53 ++++++++++++++++++ .../SecurityConnectionException.java | 52 +++++++++++++++++ src/main/java/appeng/me/GridConnection.java | 11 +++- 5 files changed, 190 insertions(+), 3 deletions(-) create mode 100644 src/api/java/appeng/api/exceptions/ExistingConnectionException.java create mode 100644 src/api/java/appeng/api/exceptions/NullNodeConnectionException.java create mode 100644 src/api/java/appeng/api/exceptions/SecurityConnectionException.java diff --git a/src/api/java/appeng/api/exceptions/ExistingConnectionException.java b/src/api/java/appeng/api/exceptions/ExistingConnectionException.java new file mode 100644 index 00000000..7c5fe25b --- /dev/null +++ b/src/api/java/appeng/api/exceptions/ExistingConnectionException.java @@ -0,0 +1,56 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2013 AlgorithmX2 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package appeng.api.exceptions; + + +import appeng.api.networking.IGridNode; + + +/** + * Exception occurred because of an already existing connection between the two {@link IGridNode}s + * + * Intended to signal an internal exception and not intended to be thrown by + * any 3rd party module. + * + * @author yueh + * @version rv3 + * @since rv3 + */ +public class ExistingConnectionException extends FailedConnection +{ + + private static final long serialVersionUID = 2975450379720353182L; + private static final String DEFAULT_MESSAGE = "Connection between both nodes already exists."; + + public ExistingConnectionException() + { + super( DEFAULT_MESSAGE ); + } + + public ExistingConnectionException( String message ) + { + super( message ); + } + +} diff --git a/src/api/java/appeng/api/exceptions/FailedConnection.java b/src/api/java/appeng/api/exceptions/FailedConnection.java index 086cea5a..de1bbc71 100644 --- a/src/api/java/appeng/api/exceptions/FailedConnection.java +++ b/src/api/java/appeng/api/exceptions/FailedConnection.java @@ -24,6 +24,22 @@ package appeng.api.exceptions; +import appeng.api.networking.IGridNode; + + +/** + * Exception indicating a failed connection between two {@link IGridNode}s. + * + * Intended to signal an internal exception and not intended to be thrown by + * any 3rd party module. + * + * See any subclass for a more specific reason. + * + * @author AlgorithmX2 + * @author yueh + * @version rv3 + * @since rv0 + */ public class FailedConnection extends Exception { @@ -32,4 +48,9 @@ public class FailedConnection extends Exception public FailedConnection() { } + + public FailedConnection( String message ) + { + super( message ); + } } diff --git a/src/api/java/appeng/api/exceptions/NullNodeConnectionException.java b/src/api/java/appeng/api/exceptions/NullNodeConnectionException.java new file mode 100644 index 00000000..8410fc7f --- /dev/null +++ b/src/api/java/appeng/api/exceptions/NullNodeConnectionException.java @@ -0,0 +1,53 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2013 AlgorithmX2 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package appeng.api.exceptions; + + +/** + * Exception due to trying to connect one or more null values. + * + * Intended to signal an internal exception and not intended to be thrown by + * any 3rd party module. + * + * @author yueh + * @version rv3 + * @since rv3 + */ +public class NullNodeConnectionException extends FailedConnection +{ + + private static final long serialVersionUID = -2143719383495321764L; + private static final String DEFAULT_MESSAGE = "Connection forged between null entities."; + + public NullNodeConnectionException() + { + super( DEFAULT_MESSAGE ); + } + + public NullNodeConnectionException( String message ) + { + super( message ); + } + +} diff --git a/src/api/java/appeng/api/exceptions/SecurityConnectionException.java b/src/api/java/appeng/api/exceptions/SecurityConnectionException.java new file mode 100644 index 00000000..d21044e8 --- /dev/null +++ b/src/api/java/appeng/api/exceptions/SecurityConnectionException.java @@ -0,0 +1,52 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2013 AlgorithmX2 + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package appeng.api.exceptions; + + +/** + * Exception due to trying to connect different security realms. + * + * Intended to signal an internal exception and not intended to be thrown by + * any 3rd party module. + * + * @author yueh + * @version rv3 + * @since rv3 + */ +public class SecurityConnectionException extends FailedConnection +{ + private static final long serialVersionUID = 5048714900434215426L; + private static final String DEFAULT_MESSAGE = "Connection failed due to different security realms."; + + public SecurityConnectionException() + { + super( DEFAULT_MESSAGE ); + } + + public SecurityConnectionException( String message ) + { + super( message ); + } + +} diff --git a/src/main/java/appeng/me/GridConnection.java b/src/main/java/appeng/me/GridConnection.java index d8f111d8..5f4314fe 100644 --- a/src/main/java/appeng/me/GridConnection.java +++ b/src/main/java/appeng/me/GridConnection.java @@ -24,7 +24,10 @@ import java.util.EnumSet; import net.minecraftforge.common.util.ForgeDirection; +import appeng.api.exceptions.ExistingConnectionException; import appeng.api.exceptions.FailedConnection; +import appeng.api.exceptions.NullNodeConnectionException; +import appeng.api.exceptions.SecurityConnectionException; import appeng.api.networking.GridFlags; import appeng.api.networking.IGridConnection; import appeng.api.networking.IGridNode; @@ -43,6 +46,8 @@ import appeng.util.ReadOnlyCollection; public class GridConnection implements IGridConnection, IPathItem { + private static final String EXISTING_CONNECTION_MESSAGE = "Connection between node [machine=%s, %s] and [machine=%s, %s] on [%s] already exists."; + private static final MENetworkChannelsChanged EVENT = new MENetworkChannelsChanged(); private int channelData = 0; private Object visitorIterationNumber = null; @@ -67,12 +72,12 @@ public class GridConnection implements IGridConnection, IPathItem AELog.info( "Security audit 2 failed at [%s] belonging to player [id=%d]", bCoordinates.toString(), b.getPlayerID() ); } - throw new FailedConnection(); + throw new SecurityConnectionException(); } if( a == null || b == null ) { - throw new GridException( "Connection Forged Between null entities." ); + throw new NullNodeConnectionException(); } if( a.hasConnection( b ) || b.hasConnection( a ) ) @@ -82,7 +87,7 @@ public class GridConnection implements IGridConnection, IPathItem final String aCoordinates = a.getGridBlock().getLocation().toString(); final String bCoordinates = b.getGridBlock().getLocation().toString(); - throw new GridException( String.format( "Connection between node [machine=%s, %s] and [machine=%s, %s] on [%s] already exists.", aMachineClass, aCoordinates, bMachineClass, bCoordinates, fromAtoB ) ); + throw new ExistingConnectionException( String.format( EXISTING_CONNECTION_MESSAGE, aMachineClass, aCoordinates, bMachineClass, bCoordinates, fromAtoB ) ); } this.sideA = a;