2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented

Add proper handling of JVMTI errors.

Reviewed-by: tbell
This commit is contained in:
Jim Holmlund 2008-07-01 09:23:00 -07:00
parent cbe7dc576f
commit 1a0c261469
2 changed files with 37 additions and 13 deletions

View File

@ -492,14 +492,17 @@ eventFilterRestricted_passesFilter(JNIEnv *env,
char *sourceName = 0; char *sourceName = 0;
jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName) jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName)
(gdata->jvmti, clazz, &sourceName); (gdata->jvmti, clazz, &sourceName);
if (error == JVMTI_ERROR_NONE) { if (error == JVMTI_ERROR_NONE &&
if (sourceName == 0 || !patternStringMatch(sourceName, desiredNamePattern)) { sourceName != 0 &&
/* We have no match */ patternStringMatch(sourceName, desiredNamePattern)) {
jvmtiDeallocate(sourceName); // got a hit - report the event
return JNI_FALSE; jvmtiDeallocate(sourceName);
} break;
} }
// We have no match, we have no source file name,
// or we got a JVM TI error. Don't report the event.
jvmtiDeallocate(sourceName); jvmtiDeallocate(sourceName);
return JNI_FALSE;
} }
break; break;
} }

View File

@ -23,7 +23,7 @@
/** /**
* @test * @test
* @bug 4836939 * @bug 4836939 6646613
* @summary JDI add addSourceNameFilter to ClassPrepareRequest * @summary JDI add addSourceNameFilter to ClassPrepareRequest
* *
* @author jjh * @author jjh
@ -31,7 +31,11 @@
* @run build TestScaffold VMConnection TargetListener TargetAdapter * @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g SourceNameFilterTest.java * @run compile -g SourceNameFilterTest.java
* @run main SourceNameFilterTest * @run main SourceNameFilterTest
* @run compile -g:none SourceNameFilterTest.java
* @run main SourceNameFilterTest
*/ */
// The compile -g:none suppresses the lineNumber table to trigger bug 6646613.
import com.sun.jdi.*; import com.sun.jdi.*;
import com.sun.jdi.event.*; import com.sun.jdi.event.*;
import com.sun.jdi.request.*; import com.sun.jdi.request.*;
@ -84,7 +88,6 @@ public class SourceNameFilterTest extends TestScaffold {
boolean gotEvent1 = false; boolean gotEvent1 = false;
boolean gotEvent2 = false; boolean gotEvent2 = false;
boolean gotEvent3 = false; boolean gotEvent3 = false;
ClassPrepareRequest cpReq; ClassPrepareRequest cpReq;
boolean shouldResume = false; boolean shouldResume = false;
SourceNameFilterTest (String args[]) { SourceNameFilterTest (String args[]) {
@ -151,6 +154,18 @@ public class SourceNameFilterTest extends TestScaffold {
*/ */
BreakpointEvent bpe = startToMain("SourceNameFilterTarg"); BreakpointEvent bpe = startToMain("SourceNameFilterTarg");
targetClass = bpe.location().declaringType(); targetClass = bpe.location().declaringType();
boolean noSourceName = false;
try {
targetClass.sourceName();
} catch (AbsentInformationException ee) {
noSourceName = true;
}
if (noSourceName) {
println("-- Running with no source names");
} else {
println("-- Running with source names");
}
mainThread = bpe.thread(); mainThread = bpe.thread();
EventRequestManager erm = vm().eventRequestManager(); EventRequestManager erm = vm().eventRequestManager();
addListener(this); addListener(this);
@ -175,7 +190,9 @@ public class SourceNameFilterTest extends TestScaffold {
/* /*
* This should cause us to get a class prepare event for * This should cause us to get a class prepare event for
* LoadedLater3 * LoadedLater3 except in the case where -g:none
* was used to compile so that there is no LineNumberTable
* and therefore, no source name for the class.
*/ */
cpReq = erm.createClassPrepareRequest(); cpReq = erm.createClassPrepareRequest();
cpReq.addSourceNameFilter("SourceNameFilterTest.java"); cpReq.addSourceNameFilter("SourceNameFilterTest.java");
@ -186,17 +203,21 @@ public class SourceNameFilterTest extends TestScaffold {
if (!gotEvent1) { if (!gotEvent1) {
failure("failure: Did not get a class prepare request " + failure("failure: Did not get a class prepare request " +
"for Loadedlater1"); "for LoadedLater1");
} }
if (gotEvent2) { if (gotEvent2) {
failure("failure: Did get a class prepare request " + failure("failure: Did get a class prepare request " +
"for Loadedlater2"); "for LoadedLater2");
} }
if (!gotEvent3) { if (gotEvent3 && noSourceName) {
failure("failure: Did get a class prepare request " +
"for LoadedLater3");
}
else if (!gotEvent3 && !noSourceName) {
failure("failure: Did not get a class prepare request " + failure("failure: Did not get a class prepare request " +
"for Loadedlater3"); "for LoadedLater3");
} }
/* /*