From 9c58e164ac4953e766b4448271fe6fc996135979 Mon Sep 17 00:00:00 2001 From: sebthom Date: Wed, 22 May 2024 16:08:16 +0200 Subject: [PATCH] feat: log some ClassCastExceptions for better troubleshooting --- .../tm4e/core/internal/grammar/raw/RawCaptures.java | 13 ++++++++++++- .../core/internal/grammar/raw/RawRepository.java | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawCaptures.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawCaptures.java index 145681d8a..de6dab054 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawCaptures.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawCaptures.java @@ -9,15 +9,26 @@ */ package org.eclipse.tm4e.core.internal.grammar.raw; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; + import org.eclipse.tm4e.core.internal.parser.PropertySettable; final class RawCaptures extends PropertySettable.HashMap implements IRawCaptures { + private static final Logger LOGGER = System.getLogger(RawCaptures.class.getName()); + private static final long serialVersionUID = 1L; @Override public IRawRule getCapture(final String captureId) { - return get(captureId); + try { + return get(captureId); + } catch (final ClassCastException ex) { + // log ClassCastException with some context, to better troubleshoot issues like https://github.com/eclipse/tm4e/issues/754 + LOGGER.log(Level.ERROR, "Unexpected ClassCastException in RawCaptures.getCapture(\"" + captureId + "\")", ex); + throw ex; + } } @Override diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawRepository.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawRepository.java index 8f430a521..420ef8d2e 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawRepository.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/grammar/raw/RawRepository.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.core.internal.grammar.raw; +import java.lang.System.Logger; +import java.lang.System.Logger.Level; import java.util.NoSuchElementException; import org.eclipse.jdt.annotation.Nullable; @@ -18,6 +20,8 @@ public final class RawRepository extends PropertySettable.HashMap implements IRawRepository { + private static final Logger LOGGER = System.getLogger(RawRepository.class.getName()); + private static final long serialVersionUID = 1L; public static final String DOLLAR_BASE = "$base"; @@ -35,7 +39,13 @@ private IRawRule getSafe(final String key) { @Override @Nullable public IRawRule getRule(final String name) { - return get(name); + try { + return get(name); + } catch (final ClassCastException ex) { + // log ClassCastException with some context, to better troubleshoot issues like https://github.com/eclipse/tm4e/issues/754 + LOGGER.log(Level.ERROR, "Unexpected ClassCastException in RawRepository.getRule(\"" + name + "\")", ex); + throw ex; + } } @Override