This is an automated email from the ASF dual-hosted git repository. entl pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 0a881f2 Fixed NPEs in Truffle debugger when SourceSection is null. 0a881f2 is described below commit 0a881f2368d8eecdf6317927e03ca809610c9190 Author: Martin Entlicher <martin.entlic...@oracle.com> AuthorDate: Mon Jun 7 15:46:38 2021 +0200 Fixed NPEs in Truffle debugger when SourceSection is null. --- .../modules/debugger/jpda/truffle/Utils.java | 9 ++++++ .../jpda/truffle/access/TruffleAccess.java | 32 +++++++++++-------- .../jpda/truffle/access/TruffleStrataProvider.java | 8 ++++- .../jpda/truffle/frames/TruffleStackFrame.java | 36 ++++++++++++---------- .../models/DebuggingTruffleActionsProvider.java | 5 ++- .../frames/models/DebuggingTruffleTreeModel.java | 7 ++++- .../jpda/truffle/frames/models/TruffleDVFrame.java | 30 +++++++++++++++--- .../debugger/jpda/truffle/source/Source.java | 8 ++++- .../debugger/jpda/backend/truffle/FrameInfo.java | 2 +- .../jpda/backend/truffle/JPDATruffleAccessor.java | 3 +- .../jpda/backend/truffle/SourcePosition.java | 32 +++++++++++-------- 11 files changed, 119 insertions(+), 53 deletions(-) diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/Utils.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/Utils.java index 2917a83..506ecda 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/Utils.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/Utils.java @@ -61,4 +61,13 @@ public final class Utils { sb.append ("</html>"); return sb.toString (); } + + public static String stringOrNull(String str) { + if ("null".equals(str)) { + return null; + } else { + return str; + } + } + } diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleAccess.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleAccess.java index 7392ee2..eaf94da 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleAccess.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleAccess.java @@ -86,6 +86,7 @@ import org.netbeans.modules.debugger.jpda.models.JPDAThreadImpl; import org.netbeans.modules.debugger.jpda.truffle.LanguageName; import org.netbeans.modules.debugger.jpda.truffle.RemoteServices; import org.netbeans.modules.debugger.jpda.truffle.TruffleDebugManager; +import org.netbeans.modules.debugger.jpda.truffle.Utils; import org.netbeans.modules.debugger.jpda.truffle.actions.StepActionProvider; import org.netbeans.modules.debugger.jpda.truffle.ast.TruffleNode; import org.netbeans.modules.debugger.jpda.truffle.frames.TruffleStackFrame; @@ -497,7 +498,12 @@ public class TruffleAccess implements JPDABreakpointListener { return null; } long id = (Long) varSrcId.createMirrorObject(); - String sourceSection = (String) sourcePositionVar.getField(VAR_SRC_SOURCESECTION).createMirrorObject(); + Field varSourceSection = sourcePositionVar.getField(VAR_SRC_SOURCESECTION); + String sourceSection = (String) varSourceSection.createMirrorObject(); + if (sourceSection == null) { + // No source section information + return null; + } Source src = Source.getExistingSource(debugger, id); if (src == null) { String name = (String) sourcePositionVar.getField(VAR_SRC_NAME).createMirrorObject(); @@ -582,26 +588,26 @@ public class TruffleAccess implements JPDABreakpointListener { sourceName = sourceDef.substring(i1, i2); i1 = i2 + 1; i2 = sourceDef.indexOf('\n', i1); - hostMethodName = sourceDef.substring(i1, i2); - if ("null".equals(hostMethodName)) { - hostMethodName = null; - } + hostMethodName = Utils.stringOrNull(sourceDef.substring(i1, i2)); i1 = i2 + 1; i2 = sourceDef.indexOf('\n', i1); sourcePath = sourceDef.substring(i1, i2); i1 = i2 + 1; i2 = sourceDef.indexOf('\n', i1); - try { - sourceURI = new URI(sourceDef.substring(i1, i2)); - } catch (URISyntaxException usex) { - throw new IllegalStateException("Bad URI: "+sourceDef.substring(i1, i2), usex); + String uriStr = Utils.stringOrNull(sourceDef.substring(i1, i2)); + if (uriStr != null) { + try { + sourceURI = new URI(uriStr); + } catch (URISyntaxException usex) { + Exceptions.printStackTrace(new IllegalStateException("Bad URI: "+sourceDef.substring(i1, i2), usex)); + sourceURI = null; + } + } else { + sourceURI = null; } i1 = i2 + 1; i2 = sourceDef.indexOf('\n', i1); - mimeType = sourceDef.substring(i1, i2); - if ("null".equals(mimeType)) { - mimeType = null; - } + mimeType = Utils.stringOrNull(sourceDef.substring(i1, i2)); i1 = i2 + 1; i2 = sourceDef.indexOf('\n', i1); if (i2 < 0) { diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleStrataProvider.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleStrataProvider.java index 464b610..a35f38f 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleStrataProvider.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/access/TruffleStrataProvider.java @@ -24,6 +24,7 @@ import java.util.List; import org.netbeans.modules.debugger.jpda.models.CallStackFrameImpl; import org.netbeans.modules.debugger.jpda.spi.StrataProvider; +import org.netbeans.modules.debugger.jpda.truffle.source.SourcePosition; import org.netbeans.spi.debugger.DebuggerServiceRegistration; /** @@ -63,7 +64,12 @@ public class TruffleStrataProvider implements StrataProvider { if (TRUFFLE_STRATUM.equals(stratum) && isInTruffleAccessPoint(csf)) { CurrentPCInfo currentPCInfo = TruffleAccess.getCurrentGuestPCInfo(csf.getThread()); if (currentPCInfo != null) { - return currentPCInfo.getSourcePosition().getStartLine(); + SourcePosition sourcePosition = currentPCInfo.getSourcePosition(); + if (sourcePosition != null) { + return sourcePosition.getStartLine(); + } else { + return 0; + } } } return csf.getLineNumber(stratum); diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/TruffleStackFrame.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/TruffleStackFrame.java index 9049d6c..19684f4 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/TruffleStackFrame.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/TruffleStackFrame.java @@ -31,6 +31,7 @@ import org.netbeans.api.debugger.jpda.JPDADebugger; import org.netbeans.api.debugger.jpda.JPDAThread; import org.netbeans.api.debugger.jpda.ObjectVariable; import org.netbeans.modules.debugger.jpda.truffle.LanguageName; +import org.netbeans.modules.debugger.jpda.truffle.Utils; import org.netbeans.modules.debugger.jpda.truffle.access.CurrentPCInfo; import org.netbeans.modules.debugger.jpda.truffle.access.TruffleAccess; import org.netbeans.modules.debugger.jpda.truffle.source.Source; @@ -115,25 +116,33 @@ public final class TruffleStackFrame { hostClassName = frameDefinition.substring(i1, i2); i1 = i2 + 1; i2 = frameDefinition.indexOf('\n', i1); - hostMethodName = stringOrNull(frameDefinition.substring(i1, i2)); + hostMethodName = Utils.stringOrNull(frameDefinition.substring(i1, i2)); i1 = i2 + 1; i2 = frameDefinition.indexOf('\n', i1); - try { - sourceURI = new URI(frameDefinition.substring(i1, i2)); - } catch (URISyntaxException usex) { - throw new IllegalStateException("Bad URI: "+frameDefinition.substring(i1, i2), usex); + String uriStr = Utils.stringOrNull(frameDefinition.substring(i1, i2)); + URI uri; + if (uriStr != null) { + try { + uri = new URI(uriStr); + } catch (URISyntaxException usex) { + Exceptions.printStackTrace(new IllegalStateException("Bad URI: "+uriStr, usex)); + uri = null; + } + } else { + uri = null; } + sourceURI = uri; i1 = i2 + 1; i2 = frameDefinition.indexOf('\n', i1); - mimeType = stringOrNull(frameDefinition.substring(i1, i2)); + mimeType = Utils.stringOrNull(frameDefinition.substring(i1, i2)); i1 = i2 + 1; if (includeInternal) { i2 = frameDefinition.indexOf('\n', i1); - sourceSection = frameDefinition.substring(i1, i2); + sourceSection = Utils.stringOrNull(frameDefinition.substring(i1, i2)); i1 = i2 + 1; internalFrame = Boolean.valueOf(frameDefinition.substring(i1)); } else { - sourceSection = frameDefinition.substring(i1); + sourceSection = Utils.stringOrNull(frameDefinition.substring(i1)); } } catch (IndexOutOfBoundsException ioob) { throw new IllegalStateException("frameDefinition='"+frameDefinition+"'", ioob); @@ -144,14 +153,6 @@ public final class TruffleStackFrame { this.isInternal = internalFrame; } - private static String stringOrNull(String str) { - if ("null".equals(str)) { - return null; - } else { - return str; - } - } - public final JPDADebugger getDebugger() { return debugger; } @@ -193,6 +194,9 @@ public final class TruffleStackFrame { } public SourcePosition getSourcePosition() { + if (sourceSection == null) { + return null; + } Source src = Source.getExistingSource(debugger, sourceId); if (src == null) { src = Source.getSource(debugger, sourceId, sourceName, hostMethodName, sourcePath, sourceURI, mimeType, codeRef); diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleActionsProvider.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleActionsProvider.java index 99c2643..b982310 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleActionsProvider.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleActionsProvider.java @@ -161,6 +161,9 @@ public class DebuggingTruffleActionsProvider implements NodeActionsProviderFilte private static void goToSource(final TruffleStackFrame f) { final SourcePosition sourcePosition = f.getSourcePosition(); + if (sourcePosition == null) { + return ; + } SwingUtilities.invokeLater (new Runnable () { @Override public void run () { @@ -239,7 +242,7 @@ public class DebuggingTruffleActionsProvider implements NodeActionsProviderFilte return false; } //return isGoToSourceSupported ((TruffleStackFrame) node); - return true; + return ((TruffleStackFrame) node).getSourcePosition() != null; } @Override diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleTreeModel.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleTreeModel.java index cb546de..10ae4a6 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleTreeModel.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/DebuggingTruffleTreeModel.java @@ -35,6 +35,7 @@ import static org.netbeans.modules.debugger.jpda.truffle.access.TruffleAccess.BA import org.netbeans.modules.debugger.jpda.truffle.actions.StepActionProvider; import org.netbeans.modules.debugger.jpda.truffle.frames.TruffleStackFrame; import org.netbeans.modules.debugger.jpda.truffle.options.TruffleOptions; +import org.netbeans.modules.debugger.jpda.truffle.source.SourcePosition; import org.netbeans.modules.debugger.jpda.ui.debugging.JPDADVFrame; import org.netbeans.modules.debugger.jpda.ui.debugging.JPDADVThread; import org.netbeans.modules.debugger.jpda.util.WeakCacheMap; @@ -312,7 +313,11 @@ public class DebuggingTruffleTreeModel implements TreeModelFilter { return false; } int linej = csf.getLineNumber(null); - int linet = tframe.getSourcePosition().getStartLine(); + SourcePosition sourcePosition = tframe.getSourcePosition(); + if (sourcePosition == null) { + return false; + } + int linet = sourcePosition.getStartLine(); return (linej == linet || linej == 0); } diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java index 15cf338..da348c2 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/frames/models/TruffleDVFrame.java @@ -24,6 +24,7 @@ import org.netbeans.modules.debugger.jpda.truffle.access.CurrentPCInfo; import org.netbeans.modules.debugger.jpda.truffle.access.TruffleAccess; import org.netbeans.modules.debugger.jpda.truffle.frames.TruffleStackFrame; import org.netbeans.modules.debugger.jpda.truffle.source.Source; +import org.netbeans.modules.debugger.jpda.truffle.source.SourcePosition; import org.netbeans.spi.debugger.ui.DebuggingView.DVFrame; import org.netbeans.spi.debugger.ui.DebuggingView.DVThread; @@ -65,7 +66,11 @@ public final class TruffleDVFrame implements DVFrame { @Override public URI getSourceURI() { - Source source = truffleFrame.getSourcePosition().getSource(); + SourcePosition sourcePosition = truffleFrame.getSourcePosition(); + if (sourcePosition == null) { + return null; + } + Source source = sourcePosition.getSource(); URI uri = source.getURI(); if (uri != null && "file".equalsIgnoreCase(uri.getScheme())) { return uri; @@ -79,18 +84,33 @@ public final class TruffleDVFrame implements DVFrame { @Override public String getSourceMimeType() { - Source source = truffleFrame.getSourcePosition().getSource(); - return source.getMimeType(); + SourcePosition sourcePosition = truffleFrame.getSourcePosition(); + if (sourcePosition != null) { + Source source = sourcePosition.getSource(); + return source.getMimeType(); + } else { + return null; + } } @Override public int getLine() { - return truffleFrame.getSourcePosition().getStartLine(); + SourcePosition sourcePosition = truffleFrame.getSourcePosition(); + if (sourcePosition != null) { + return sourcePosition.getStartLine(); + } else { + return -1; + } } @Override public int getColumn() { - return truffleFrame.getSourcePosition().getStartColumn(); + SourcePosition sourcePosition = truffleFrame.getSourcePosition(); + if (sourcePosition != null) { + return sourcePosition.getStartColumn(); + } else { + return -1; + } } } diff --git a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java index 25289f2..1d618d3 100644 --- a/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java +++ b/java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/source/Source.java @@ -86,7 +86,7 @@ public final class Source { this.mimeType = mimeType; this.hash = hash; } - + public static Source getExistingSource(JPDADebugger debugger, long id) { synchronized (KNOWN_SOURCES) { Map<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger); @@ -146,6 +146,9 @@ public final class Source { URI uri, String mimeType, StringReference codeRef) { + if (uri == null && codeRef == null) { + return null; + } synchronized (KNOWN_SOURCES) { Map<Long, Source> dbgSources = KNOWN_SOURCES.get(debugger); if (dbgSources != null) { @@ -209,6 +212,9 @@ public final class Source { } public String getContent() { + if (codeRef == null) { + return null; + } synchronized (this) { if (content == null) { try { diff --git a/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/FrameInfo.java b/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/FrameInfo.java index 03c4e41..b5214c6 100644 --- a/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/FrameInfo.java +++ b/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/FrameInfo.java @@ -65,7 +65,7 @@ final class FrameInfo { DebuggerVisualizer.getSourceLocation(topStackFrame, isHost) + "\n" + position.id + "\n" + position.name + "\n" + position.path + "\n" + position.hostClassName + "\n" + position.hostMethodName + "\n" + - position.uri.toString() + "\n" + position.mimeType + "\n" + position.sourceSection + "\n" + + position.uri + "\n" + position.mimeType + "\n" + position.sourceSection + "\n" + isInternal(topStackFrame); topVariables = JPDATruffleAccessor.getVariables(topStackFrame); } diff --git a/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/JPDATruffleAccessor.java b/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/JPDATruffleAccessor.java index d812372..8fbdfa9 100644 --- a/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/JPDATruffleAccessor.java +++ b/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/JPDATruffleAccessor.java @@ -39,6 +39,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -309,7 +310,7 @@ public class JPDATruffleAccessor extends Object { str.append('\n'); str.append(position.hostMethodName); str.append('\n'); - str.append(position.uri.toString()); + str.append(Objects.toString(position.uri)); str.append('\n'); str.append(position.mimeType); str.append('\n'); diff --git a/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/SourcePosition.java b/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/SourcePosition.java index 1e93a19..3efe34a 100644 --- a/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/SourcePosition.java +++ b/java/debugger.jpda.truffle/truffle-backend/org/netbeans/modules/debugger/jpda/backend/truffle/SourcePosition.java @@ -47,20 +47,26 @@ final class SourcePosition { final String mimeType; public SourcePosition(SourceSection sourceSection, LanguageInfo languageInfo) { - Source source = sourceSection.getSource(); - this.id = getId(source); - this.name = source.getName(); - this.hostClassName = null; - this.hostMethodName = null; - String sourcePath = source.getPath(); - if (sourcePath == null) { - sourcePath = name; + if (sourceSection != null) { + Source source = sourceSection.getSource(); + this.id = getId(source); + this.name = source.getName(); + this.hostClassName = null; + this.hostMethodName = null; + String sourcePath = source.getPath(); + if (sourcePath == null) { + sourcePath = name; + } + this.path = sourcePath; + this.sourceSection = sourceSection.getStartLine() + "," + sourceSection.getStartColumn() + "," + sourceSection.getEndLine() + "," + sourceSection.getEndColumn(); + this.code = source.getCharacters().toString(); + this.uri = source.getURI(); + this.mimeType = findMIMEType(source, languageInfo); + } else { + this.id = -1; + this.name = this.hostClassName = this.hostMethodName = this.path = this.sourceSection = this.code = this.mimeType = null; + this.uri = null; } - this.path = sourcePath; - this.sourceSection = sourceSection.getStartLine() + "," + sourceSection.getStartColumn() + "," + sourceSection.getEndLine() + "," + sourceSection.getEndColumn(); - this.code = source.getCharacters().toString(); - this.uri = source.getURI(); - this.mimeType = findMIMEType(source, languageInfo); } public SourcePosition(StackTraceElement ste) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists