2157677: ClassPrepareRequest.addSourceNameFilter() does not behave as documented
Summary: Add proper handling of JVMTI errors.
Reviewed-by: tbell
--- a/jdk/src/share/back/eventFilter.c Mon Jun 30 14:11:49 2008 -0700
+++ b/jdk/src/share/back/eventFilter.c Tue Jul 01 09:23:00 2008 -0700
@@ -492,14 +492,17 @@
char *sourceName = 0;
jvmtiError error = JVMTI_FUNC_PTR(gdata->jvmti,GetSourceFileName)
(gdata->jvmti, clazz, &sourceName);
- if (error == JVMTI_ERROR_NONE) {
- if (sourceName == 0 || !patternStringMatch(sourceName, desiredNamePattern)) {
- /* We have no match */
- jvmtiDeallocate(sourceName);
- return JNI_FALSE;
- }
+ if (error == JVMTI_ERROR_NONE &&
+ sourceName != 0 &&
+ patternStringMatch(sourceName, desiredNamePattern)) {
+ // got a hit - report the event
+ 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);
+ return JNI_FALSE;
}
break;
}
--- a/jdk/test/com/sun/jdi/SourceNameFilterTest.java Mon Jun 30 14:11:49 2008 -0700
+++ b/jdk/test/com/sun/jdi/SourceNameFilterTest.java Tue Jul 01 09:23:00 2008 -0700
@@ -23,7 +23,7 @@
/**
* @test
- * @bug 4836939
+ * @bug 4836939 6646613
* @summary JDI add addSourceNameFilter to ClassPrepareRequest
*
* @author jjh
@@ -31,7 +31,11 @@
* @run build TestScaffold VMConnection TargetListener TargetAdapter
* @run compile -g SourceNameFilterTest.java
* @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.event.*;
import com.sun.jdi.request.*;
@@ -84,7 +88,6 @@
boolean gotEvent1 = false;
boolean gotEvent2 = false;
boolean gotEvent3 = false;
-
ClassPrepareRequest cpReq;
boolean shouldResume = false;
SourceNameFilterTest (String args[]) {
@@ -151,6 +154,18 @@
*/
BreakpointEvent bpe = startToMain("SourceNameFilterTarg");
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();
EventRequestManager erm = vm().eventRequestManager();
addListener(this);
@@ -175,7 +190,9 @@
/*
* 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.addSourceNameFilter("SourceNameFilterTest.java");
@@ -186,17 +203,21 @@
if (!gotEvent1) {
failure("failure: Did not get a class prepare request " +
- "for Loadedlater1");
+ "for LoadedLater1");
}
if (gotEvent2) {
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 " +
- "for Loadedlater3");
+ "for LoadedLater3");
}
/*