diff --git a/src/Analysis/Problem/Bukkit/ChunkLoadExceptionProblem.php b/src/Analysis/Problem/Bukkit/ChunkLoadExceptionProblem.php index 621448f..e3a9590 100644 --- a/src/Analysis/Problem/Bukkit/ChunkLoadExceptionProblem.php +++ b/src/Analysis/Problem/Bukkit/ChunkLoadExceptionProblem.php @@ -9,6 +9,21 @@ class ChunkLoadExceptionProblem extends BukkitProblem { + /** + * The start of the error and the lines after it, up to the start of the line that shows the cause. + * Whole lines are skipped possessively, so a long stack trace doesn't exhaust the backtrack limit. + * + * Example: "Encountered an unexpected exception\njava.lang.NullPointerException\n" + */ + protected const string UNEXPECTED_EXCEPTION = 'Encountered an unexpected exception\n(?:.*+\n)*?'; + + /** + * The start of a stack trace line up to the simple class name + * + * Example: "\tat net.minecraft.server.v1_8_R3." + */ + protected const string STACK_TRACE_PACKAGE = '\h*at (?:[\w$]++\.)*'; + /** * @inheritDoc */ @@ -18,14 +33,19 @@ public function getMessage(): string } /** + * Examples below UNEXPECTED_EXCEPTION: + * "at net.minecraft.server.v1_8_R3.ChunkRegionLoader.loadChunk(ChunkRegionLoader.java:70)" + * "at net.minecraft.server.v1_8_R3.ChunkRegionLoader.loadEntities(ChunkRegionLoader.java:433)" + * "net.minecraft.server.v1_13_R1.ReportedException: Exception generating new chunk" + * * @inheritDoc */ public static function getPatterns(): array { return [ - '/Encountered an unexpected exception(\n.*)*at.*ChunkRegionLoader\.loadChunk/', - '/Encountered an unexpected exception(\n.*)*at.*ChunkRegionLoader\.loadEntities/', - '/Encountered an unexpected exception(\n.*)*Exception generating new chunk/', + '/' . static::UNEXPECTED_EXCEPTION . static::STACK_TRACE_PACKAGE . 'ChunkRegionLoader\.loadChunk/', + '/' . static::UNEXPECTED_EXCEPTION . static::STACK_TRACE_PACKAGE . 'ChunkRegionLoader\.loadEntities/', + '/' . static::UNEXPECTED_EXCEPTION . '(?:[\w.$]++: )*Exception generating new chunk/', '/Couldn\'t load chunk\n/' ]; } diff --git a/test/tests/Performance/PatternSafetyTest.php b/test/tests/Performance/PatternSafetyTest.php index 8832e35..53da58e 100644 --- a/test/tests/Performance/PatternSafetyTest.php +++ b/test/tests/Performance/PatternSafetyTest.php @@ -3,7 +3,6 @@ namespace Aternos\Codex\Minecraft\Test\Performance; use Aternos\Codex\Analysis\PatternInsightInterface; -use Aternos\Codex\Minecraft\Analysis\Problem\Bukkit\ChunkLoadExceptionProblem; use Aternos\Codex\Minecraft\Analysis\Problem\Forge\ClientOnlyModProblem; use Aternos\Codex\Minecraft\Analysis\Problem\Forge\ModDependencyProblem; use Aternos\Codex\Minecraft\Analysis\Problem\Forge\ModFatalProblem; @@ -76,7 +75,6 @@ class PatternSafetyTest extends TestCase * Which of them actually fails depends on whether PCRE JIT is enabled. */ protected const array KNOWN_UNSAFE_PATTERNS = [ - ChunkLoadExceptionProblem::class => [0, 1, 2], ClientOnlyModProblem::class => [0], ModDependencyProblem::class => ["loading-failed-exception"], ModFatalProblem::class => ["failed-to-load"],