playframework / play1

Play framework
https://www.playframework.com/documentation/1.4.x/home
Other
1.58k stars 683 forks source link

PlayStatusPlugin method computeApplicationStatus throws ClassCastException #1436

Open Alexandermjos opened 1 year ago

Alexandermjos commented 1 year ago

Hi. I noticed that PlayStatusPlugin throws an ClassCastException when the input json=true.

Steps to reproduce: String playStatus = new PlayStatusPlugin().computeApplicationStatus(true);

image

Anyone else get this error?

It works fine if input to method is false.

Play Version (1.7.1 )

Operating System (Windows 11)

JDK

openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment Temurin-11.0.12+7 (build 11.0.12+7) OpenJDK 64-Bit Server VM Temurin-11.0.12+7 (build 11.0.12+7, mixed mode)

rakix commented 1 year ago

The text format of "play status" is fine, so I think it will work if we do the same for the JSON format.


===================================================================
diff --git a/framework/src/play/plugins/PlayStatusPlugin.java b/framework/src/play/plugins/PlayStatusPlugin.java
--- a/framework/src/play/plugins/PlayStatusPlugin.java  (revision 7bd07799819b33373f0a0e517061ebcd8fa18411)
+++ b/framework/src/play/plugins/PlayStatusPlugin.java  (date 1683015670469)
@@ -225,20 +225,24 @@
         {
             JsonArray monitors = new JsonArray();
             try {
-                Object[][] data = Misc.sort(MonitorFactory.getRootMonitor().getBasicData(), 3, "desc");
-                for (Object[] row : data) {
-                    if (((Double) row[1]) > 0) {
+                List<Monitor> ms = new ArrayList<>(asList(MonitorFactory.getRootMonitor().getMonitors()));
+                ms.sort((m1, m2) -> Double.compare(m2.getTotal(), m1.getTotal()));
+                for (Monitor m : ms) {
+                    if (m.getHits() > 0) {
                         JsonObject o = new JsonObject();
-                        o.addProperty("name", row[0].toString());
-                        o.addProperty("hits", (Double) row[1]);
-                        o.addProperty("avg", (Double) row[2]);
-                        o.addProperty("min", (Double) row[6]);
-                        o.addProperty("max", (Double) row[7]);
+                        o.addProperty("name", m.getLabel());
+                        o.addProperty("hits", m.getHits());
+                        o.addProperty("avg", m.getAvg());
+                        o.addProperty("min", m.getAvg());
+                        o.addProperty("max", m.getMax());
                         monitors.add(o);
                     }
                 }
+
             } catch (Exception e) {
-                e.printStackTrace();
+                JsonObject o = new JsonObject();
+                o.addProperty("exception",e.getMessage());
+                monitors.add(o);
             }
             status.add("monitors", monitors);
         }