From 560e11381e6303798c6939b0f3a7dbe2eb6f1970 Mon Sep 17 00:00:00 2001 From: Leo Woerteler Date: Thu, 26 Mar 2015 15:47:53 +0100 Subject: [PATCH] [FIX] XQuery, GH-1115: NPE in `prof:variables()` when variable is not yet bound. --- .../src/main/java/org/basex/query/var/QueryStack.java | 8 +++++--- .../test/java/org/basex/query/func/ProfModuleTest.java | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/basex-core/src/main/java/org/basex/query/var/QueryStack.java b/basex-core/src/main/java/org/basex/query/var/QueryStack.java index 1fa763b39e..c3dc478343 100644 --- a/basex-core/src/main/java/org/basex/query/var/QueryStack.java +++ b/basex-core/src/main/java/org/basex/query/var/QueryStack.java @@ -131,9 +131,11 @@ public void set(final Var var, final Value val, final QueryContext qc, final Inp */ public String dump() { final StringBuilder sb = new StringBuilder(QueryText.DEBUGLOCAL + ':'); - for(int i = end - 1; i >= 0; i--) { - sb.append(Prop.NL).append(" $").append(vars[i].name).append(" := ").append(stack[i]); - if(i == start && i > 0) sb.append(Prop.NL).append(QueryText.DEBUGGLOBAL + ':'); + for(int i = end; --i >= 0;) { + if(vars[i] != null) { + sb.append(Prop.NL).append(" $").append(vars[i].name).append(" := ").append(stack[i]); + if(i == start && i > 0) sb.append(Prop.NL).append(QueryText.DEBUGGLOBAL + ':'); + } } return sb.toString(); } diff --git a/basex-core/src/test/java/org/basex/query/func/ProfModuleTest.java b/basex-core/src/test/java/org/basex/query/func/ProfModuleTest.java index 6576739e6d..75a66b9ebf 100644 --- a/basex-core/src/test/java/org/basex/query/func/ProfModuleTest.java +++ b/basex-core/src/test/java/org/basex/query/func/ProfModuleTest.java @@ -76,6 +76,7 @@ public void variables() { try { System.setErr(NULL); query("for $x in 1 to 2 return " + _PROF_VARIABLES.args(), ""); + query(_PROF_VARIABLES.args() + ", let $x := random:double() return floor($x * $x)", "0"); } finally { System.setErr(ERR); }