From 27193999fca3c64f0d010ca03a4eee71f7dd7d20 Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Sun, 10 Jan 2021 20:38:26 +0100 Subject: [PATCH] Add error handling for missing match ids --- .../tippliga/TLWMatchesUpdaterFootball.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java b/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java index aa5740f..6335457 100644 --- a/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java +++ b/src/main/java/de/jeyp91/tippliga/TLWMatchesUpdaterFootball.java @@ -146,8 +146,12 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { ArrayList missingMatches = new ArrayList<>(); for(APIFootballMatch apiFootballMatch : apiFootballMatches) { - if(getMatchingMatch(apiFootballMatch, tlwMatches) == null) { - missingMatches.add(apiFootballMatch); + try { + if(getMatchingMatch(apiFootballMatch, tlwMatches) == null) { + missingMatches.add(apiFootballMatch); + } + } catch (NullPointerException ignored) { + } } @@ -171,12 +175,16 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { ArrayList apiFootballMatches) { for(APIFootballMatch apiFootballMatch : apiFootballMatches) { - TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches); - if(tlwMatch == null) { - StatusHolder.setError(); - logger.error("Did not find match to update: " + this.season + ", " + this.league + ", " + tlwMatches.get(0).getMatchday() + ", " + apiFootballMatch.getTeamNameHome() + " - " + apiFootballMatch.getTeamNameGuest()); + try { + TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches); + if(tlwMatch == null) { + StatusHolder.setError(); + logger.error("Did not find match to update: " + this.season + ", " + this.league + ", " + tlwMatches.get(0).getMatchday() + ", " + apiFootballMatch.getTeamNameHome() + " - " + apiFootballMatch.getTeamNameGuest()); + } + tlwMatch.setMatchDateTime(apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19)); + } catch(NullPointerException ignored) { + } - tlwMatch.setMatchDateTime(apiFootballMatch.getMatchDateTime().replace("T", " ").substring(0, 19)); } } @@ -200,12 +208,16 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { ArrayList apiFootballMatches) { for(APIFootballMatch apiFootballMatch : apiFootballMatches) { - TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches); - tlwMatch.setShowTable(apiFootballMatch.getShowTable()); + try { + TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches); + tlwMatch.setShowTable(apiFootballMatch.getShowTable()); + } catch (NullPointerException ignored) { + + } } } - private TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList tlwMatches) { + private TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList tlwMatches) throws NullPointerException{ int foundMatches = 0; TLWMatch matchingMatch = null; for(TLWMatch match : tlwMatches) {