如何在java程序中禁用堆栈跟踪生成? [英] How to disable stack trace generation in a java program?

查看:114
本文介绍了如何在java程序中禁用堆栈跟踪生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用在抛出异常时生成的堆栈跟踪。
我使用过,

I want to disable the stack trace getting generated when an exception is thrown. I have used,

Runtime.getRuntime().traceInstructions(false);
Runtime.getRuntime().traceMethodCalls(false);

但是我仍然可以看到生成的跟踪。你怎么能这样做?另外我需要检测是否有人正在调试我的课程。

but still i could see the trace getting generated. How can you do that? Also i need to detect whether some one is debugging my class.

我想禁用所有的异常跟踪。我不能使用混淆,因为我的产品是一个将用于开发的SDK。我提供一个运行时,当人们想要部署使用我的SDK构建的应用程序时使用。我的要求是任何使用我的运行时jar的人都不应该能够调试编写的代码...或者至少我会通过避免从我的运行时jar生成堆栈跟踪来进行调试。

I want to disable all exception traces. I cannot use obfuscation since my product is an SDK which will be used in development. I am offering a Runtime also which is used when people want to deploy their applications built using my SDK. My requirement is that anyone using my Runtime jars should not be able to debug the code that is written...or atleast i will make it tough to debug by avoiding the stack trace generation from my runtime jars.

我发现的一种方法是源自我的运行时jar的所有异常,我只是抓住他们,并在异常对象上设置一个空的StackTraceElement数组,重新抛出它...

One way that i have found is that all the exceptions that are originating from my runtime jars, i would just catch them and set an empty StackTraceElement array on the exception object and re-throw it...

为什么这样的要求?
假设你使用我的SDK开发一个应用程序(SDK jar不能与你的应用程序绑定...限制它,那是最后:) !!)现在运行您的应用程序在客户端的机器上(或客户端)需要在客户端的机器上安装Runtime,并运行应用程序。现在,如果您的客户端使用我的Runtime jar开始自己的应用程序呢?这是对我的业务的威胁....这是为什么可怕的要求。

Why such requirement? Suppose you a develop an application using my SDK.(SDK jars cannot bundled with your application..i have restricted it and thats final :) !!) Now to run your application on your client's machine you(or client) needs to install the Runtime on client's machine and run your application. Now what if your client starts developing his own applications using my Runtime jars!! Thats a threat to my business....Thats why the horrible requirement.

为什么要禁用堆栈跟踪?

通过禁用堆栈跟踪生成或方法调用跟踪生成,我想让我的Runtime jar开发代码困难,这就是为什么我以这种方式开始我的问题...建议一些其他解决方案来实现这样的要求...

Why disable stack trace?
By disabling the stack trace generation or method call trace generation i wanted to make developing code with my Runtime jars difficult and thats why i started my question in that way...do suggest some other solution to achieve such a requirement...

推荐答案

JVM有一些错综复杂的部分(至少Sun的JVM实现),如果堆栈跟踪生成被禁用(我在执行一些支持反射方法时看到这一点),则该方法不起作用。所以我不认为可以禁用堆栈跟踪生成。 Runtime.trace *()方法是关于别的东西(调试工具比堆栈跟踪更彻底)。

There are a few intricate parts of the JVM (at least, Sun's implementation of the JVM) which do not work if stack trace generation is disabled (I saw this in the implementation of some support methods for reflection). So I do not think that stack trace generation can be disabled at all. The Runtime.trace*() methods are about something else (a debugging tool much more thorough than stack traces).

在所有通用性中,只有通过字节码检测(加载时使用额外的指令修改了字节码),才能透明地分析任何Java代码。唯一已知的防范这种分析(我假设你试图保护你的代码内部机密)是一个混淆。参见 ProGuard 。混淆会使堆栈跟踪任何过于好奇的用户无效(而且,由于同样的原因,令人遗憾的是,这也使调试变得非常困难)。

In all generality, any Java code can be transparently analyzed, if only through bytecode instrumentation (bytecode modified with extra instructions when it is loaded). The only known defense against such analysis (I am assuming that you are trying to keep your code internals confidential) is obfuscation. See for instance ProGuard. Obfuscation will make stack traces useless to any over-inquisitive user (and, sadly, it also makes debugging very difficult, for the same reasons).

这篇关于如何在java程序中禁用堆栈跟踪生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆