Exception when using the diff tool

I am trying to write a diff tool which fetches files from a repository and compares it against the local copy.

I get an exception:

Wrote the file
polaris/src/com/collation/proxy/clientproxy/common/DetailsPanelInterface.java
in dir c:\temp
java.lang.NullPointerException
at java.io.Writer.write(Writer.java:126)
at java.io.PrintWriter.newLine(PrintWriter.java:408)
at java.io.PrintWriter.println(PrintWriter.java:559)
at java.io.PrintWriter.println(PrintWriter.java:684)
at java.lang.Throwable.printStackTrace(Throwable.java:510)
at
com.intellij.openapi.editor.impl.EditorFactoryImpl.a(EditorFactoryImpl.java:53)
at
com.intellij.openapi.editor.impl.EditorFactoryImpl.createEditor(EditorFactoryImpl.java:47)
at
com.intellij.openapi.diff.impl.DiffUtil.createEditor(DiffUtil.java:18)
at
com.intellij.openapi.diff.impl.highlighting.EditorPlaceHolder.setContent(EditorPlaceHolder.java:0)
at
com.intellij.openapi.diff.impl.highlighting.DiffPanelState$1.run(DiffPanelState.java)
at
com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:370)
at
com.intellij.openapi.diff.impl.highlighting.DiffPanelState.setContents(DiffPanelState.java:5)
at
com.intellij.openapi.diff.impl.DiffPanelImpl.setContents(DiffPanelImpl.java:24)
at
com.intellij.openapi.diff.impl.DiffPanelImpl.setDiffRequest(DiffPanelImpl.java:140)
at
com.intellij.openapi.diff.impl.external.DiffManagerImpl.createDiffPanel(DiffManagerImpl.java:12)
at
com.intellij.openapi.diff.impl.external.FrameDiffTool.a(FrameDiffTool.java:1)
at
com.intellij.openapi.diff.impl.external.FrameDiffTool.show(FrameDiffTool.java:25)
at
com.intellij.openapi.diff.impl.external.CompositeDiffTool.show(CompositeDiffTool.java:10)
at
plugin.cmvc.ui.CompareToRepositoryAction.actionPerformed(CompareToRepositoryAction.java:68)
at
com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:13)
at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at
com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:44)
at com.intellij.ui.plaf.beg.BegMenuItemUI.a(BegMenuItemUI.java:7)
at
com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:114)
at
com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:6)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at
java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at
java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at
com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:94)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:120)
at
com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Process finished with exit code 0

I have attached the source code for this file.


try {
SimpleDiffRequest diffData = new
SimpleDiffRequest(myProject,myFile.getPresentableUrl());
diffData.setContentTitles("From repository", "Local
file");
DiffContent currentContent =
FileContent.fromFile(myProject, myFile);
DiffContent vssContent =
SimpleContent.fromIoFile(myTmpFile,
myFile.getCharset().name(),
currentContent.getContentType());
diffData.setContents(vssContent, currentContent);
DiffManager.getInstance().getDiffTool().show(diffData);
}
catch (IOException ex) {
ex.printStackTrace();
}

I debugged this and both currentContent and vssContent seem to have valid
values. The content in vssContent actually shows the file content.

Can you please let me know what I am messing up?



Attachment(s):
CompareToRepositoryAction.java
3 comments

java.lang.NullPointerException
at java.io.Writer.write(Writer.java:126)
at java.io.PrintWriter.newLine(PrintWriter.java:408)


This is something really odd. According to my JDK sources, the system-property "line.separator" is null in your VM that makes the Throwable.printStackTrace() fail. Once you fix that all should be good.

Sascha

0

Thanks a tonne.

I have a properties file for the plugin and I did a System.setProperties(properties) with that.

What it did was it blanked out all the default system properties including line.separator!

Lesson learnt.

Thanks again, this was very helpful.

0

For posterity, this is the code I used. ["Inspired" by the VSS diff plugin].

public void actionPerformed(AnActionEvent e) {
try {
String fileName = Util.getFileName(e);
DataContext dataContext = e.getDataContext();
myFile = (VirtualFile) dataContext.getData(DataConstants.VIRTUAL_FILE);
Project myProject = (Project)dataContext.getData(DataConstants.PROJECT);

if (myFile != null) {
String extension = myFile.getExtension();
String s = "." + extension;

myTmpFile = new File(Props.getTmpDir(), fileName);
myTmpFile.deleteOnExit();

//get the file from repository.
//This varies for your need.
System.out.println("Getting file from repository");
ExtractFile extractFile = new ExtractFile(fileName, Props.getTmpDir(),myProject);
extractFile.go();
System.out.println("Wrote the file " + fileName + " in dir " + Props.getTmpDir());
try {
SimpleDiffRequest diffData = new SimpleDiffRequest(myProject,myFile.getPresentableUrl());
diffData.setContentTitles("From repository", "Local file");
DiffContent currentContent = FileContent.fromFile(myProject, myFile);
DiffContent vssContent = SimpleContent.fromIoFile(myTmpFile,
myFile.getCharset().name(), currentContent.getContentType());
diffData.setContents(vssContent, currentContent);
DiffManager.getInstance().getDiffTool().show(diffData);
}
catch (IOException ex) {
ex.printStackTrace();
}
}
} catch (Exception e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}

0

Please sign in to leave a comment.