Language: Java
Label: safe
CWE: CWE-502 \u2014 Deserialization of Untrusted Data
The product deserializes untrusted data without sufficiently verifying that the resulting data will be valid.

Code:
	protected int getNextConnectSatelliteId(boolean prev, int x, int y) {
		final List<ExitRoute> routes = getRoutedPipe().getRouter().getIRoutersByCost();
		int closestIdFound = prev ? 0 : Integer.MAX_VALUE;
		for (final BaseLogicSatellite satellite : BaseLogicSatellite.AllSatellites) {
			CoreRoutedPipe satPipe = satellite.getRoutedPipe();
			if(satPipe == null || satPipe.stillNeedReplace() || satPipe.getRouter() == null)
				continue;
			IRouter satRouter = satPipe.getRouter();
			for (ExitRoute route:routes){
				if (route.destination == satRouter) {
					if(x == -1 && y == -1) {
						if (!prev && satellite.satelliteId > satelliteId && satellite.satelliteId < closestIdFound) {
							closestIdFound = satellite.satelliteId;
						} else if (prev && satellite.satelliteId < satelliteId && satellite.satelliteId > closestIdFound) {
							closestIdFound = satellite.satelliteId;
						}
					} else if(y == -1) {
						if (!prev && satellite.satelliteId > advancedSatelliteIdArray[x] && satellite.satelliteId < closestIdFound) {
							closestIdFound = satellite.satelliteId;
						} else if (prev && satellite.satelliteId < advancedSatelliteIdArray[x] && satellite.satelliteId > closestIdFound) {
							closestIdFound = satellite.satelliteId;
						}
					} else {
						//TODO
					}
				}
			}
		}
		if (closestIdFound == Integer.MAX_VALUE) {
			if(x == -1 && y == -1) {
				return satelliteId;
			} else if(y == -1) {
				return advancedSatelliteIdArray[x];
			} else {
				//TODO
			}
		}

		return closestIdFound;

	}