Skip to content

Commit 07006b5

Browse files
author
Sam Pullara
committed
found a bug in inverted -- didnt allow for Future false
1 parent 45f14d8 commit 07006b5

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

core/src/main/java/com/sampullara/mustache/Mustache.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.NoSuchElementException;
1717
import java.util.concurrent.Callable;
1818
import java.util.concurrent.ConcurrentHashMap;
19+
import java.util.concurrent.ExecutionException;
1920
import java.util.concurrent.Future;
2021
import java.util.concurrent.atomic.AtomicInteger;
2122
import java.util.logging.Level;
@@ -510,12 +511,23 @@ protected Iterable<Scope> inverted(final Scope s, final String name) {
510511
String traceName = parent == null ? s.getClass().getName() : parent.getClass().getName();
511512
event = MustacheTrace.addEvent("inverted: " + name, traceName);
512513
}
513-
final Object value = getValue(s, name);
514+
Object possibleFuture = getValue(s, name);
515+
while (possibleFuture instanceof Future) {
516+
try {
517+
possibleFuture = ((Future) possibleFuture).get();
518+
} catch (Exception e) {
519+
logger.log(Level.SEVERE, "Could not get inverted: " + name, e);
520+
return null;
521+
}
522+
}
523+
final Object value = possibleFuture;
514524
if (trace) {
515525
event.end();
516526
}
527+
517528
boolean isntEmpty = value instanceof Iterable && ((Iterable) value).iterator().hasNext();
518-
if (isntEmpty || (value instanceof Boolean && ((Boolean) value)) ||
529+
if (isntEmpty ||
530+
(value instanceof Boolean && ((Boolean) value)) ||
519531
(value != null && !(value instanceof Iterable) && !(value instanceof Boolean))) {
520532
return EMPTY;
521533
}

core/src/main/java/com/sampullara/mustache/MustacheTrace.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public static class Event {
2727
public String name;
2828
public String parameter;
2929

30-
public Event(String name, String parameter, String unique) {
30+
public Event(String name, String parameter, String thread) {
3131
this.name = name;
3232
this.parameter = parameter;
33-
this.thread = unique;
33+
this.thread = thread;
3434
}
3535

3636
public String toString() {

nodetest.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ fs.readFile("src/test/resources/complex.html", function(err, data) {
2323
var html = m.to_html(template, view);
2424
var start = new Date().getTime();
2525
var total = 0;
26+
sys.puts(m.to_html(template, view));
2627
while(true) {
2728
m.to_html(template, view);
2829
total++;
29-
if (new Date().getTime() - start > 1000) {
30+
if (new Date().getTime() - start > 5000) {
3031
break;
3132
}
3233
}
33-
sys.puts(total);
34+
sys.puts(total / 5);
3435
});
3536

0 commit comments

Comments
 (0)