Skip to content

Commit

Permalink
IDEA-324233 Add assertion for OLD_EDT actions 2
Browse files Browse the repository at this point in the history
`IdeaLogger.isTooFrequentException` deduplicates reports on a per-stacktrace basis. Deprecation problems do not depend on stacktrace.

Also, improve the message.

GitOrigin-RevId: 7dcf2ad539199956b8b4fd3d51745869a4185c1a
  • Loading branch information
gregsh authored and intellij-monorepo-bot committed Jan 23, 2024
1 parent 41d2faf commit 071257f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
25 changes: 20 additions & 5 deletions platform/core-api/src/com/intellij/diagnostic/PluginException.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.openapi.diagnostic.ExceptionWithAttachments;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -112,13 +113,27 @@ public static void logPluginError(@NotNull Logger logger,
}

public static void reportDeprecatedUsage(@NotNull String signature, @NotNull String details) {
String message = "'" + signature + "' is deprecated and going to be removed soon. " + details;
Logger.getInstance(PluginException.class).error(message);
String message = "`" + signature + "` is deprecated and going to be removed soon. " + details;
PluginException t = new PluginException(message, null);
// trim stacktrace to avoid multiple reports in logs with the same deprecated signature
t.setStackTrace(ArrayUtil.realloc(t.getStackTrace(), 3, StackTraceElement[]::new));
Logger.getInstance(PluginException.class).error(t);
}

public static void reportDeprecatedUsage(@NotNull Class<?> violator, @NotNull String signature, @NotNull String details) {
String message = "`" + signature + "` is deprecated and going to be removed soon. " + details;
PluginException t = createByClass(message, null, violator);
// trim stacktrace to avoid multiple reports in logs with the same deprecated signature
t.setStackTrace(ArrayUtil.realloc(t.getStackTrace(), 5, StackTraceElement[]::new));
Logger.getInstance(violator).error(t);
}

public static void reportDeprecatedDefault(@NotNull Class<?> violator, @NotNull String methodName, @NotNull String details) {
String message = "The default implementation of method '" + methodName + "' is deprecated, " +
"you need to override it in '" + violator + "'. " + details;
Logger.getInstance(violator).error(createByClass(message, null, violator));
String message = "The default implementation of method `" + methodName + "` is deprecated, " +
"`" + violator.getName() + "` must override it. " + details;
PluginException t = createByClass(message, null, violator);
// trim stacktrace to avoid multiple reports in logs with the same deprecated method
t.setStackTrace(ArrayUtil.realloc(t.getStackTrace(), 5, StackTraceElement[]::new));
Logger.getInstance(violator).error(t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public interface ActionUpdateThreadAware {
if (this instanceof UpdateInBackground && ((UpdateInBackground)this).isUpdateInBackground()) {
return ActionUpdateThread.BGT;
}
PluginException.reportDeprecatedDefault(getClass(), "getActionUpdateThread", "OLD_EDT is deprecated for removal");
PluginException.reportDeprecatedUsage(
getClass(), "ActionUpdateThread.OLD_EDT",
"'" + getClass().getName() + "' must override `getActionUpdateThread` and chose EDT or BGT. See ActionUpdateThread javadoc.");
return ActionUpdateThread.OLD_EDT;
}

Expand Down

0 comments on commit 071257f

Please sign in to comment.