Markes dump displays nulls for IMarker.LINE_NUMBER and IMarker.CHAR_START Plugin development markers - eclipse

I have following generic code that dumps all the markers with all the attibutes in the system. If I set some breakpoints the value for both LINE_NUMBER and IMarker.CHAR_START is always displaed as null despite them having a clear value.
Can Anybody help understand that?
private void printAllMarkers() {
IMarker[] markers = null;
IWorkspace root = ResourcesPlugin.getWorkspace();
IProject projects[] = root.getRoot().getProjects();
for (IProject p : projects) {
try {
markers = p.findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
System.out.println("\nAll Markers Are: ");
for (IMarker m : markers) {
System.out.println("-----------Marker of Type: " + m.getType());
dumpMarker(m);
}
} catch (CoreException e) {
e.printStackTrace();
}
}
}
public static void dumpMarker(IMarker m) {
try {
for (String attrName : m.getAttributes().keySet()) {
System.out.println("Attribute:" + attrName + "=" + m.getAttribute(attrName, null));
}
} catch (CoreException e) {
e.printStackTrace();
}
}

I found the problem. It's an Eclipse bug that displays the value as null if it comes from a 'supertype"
so getAttribute(attrName, null) will return null for lineStart even if the attribute exists.

Related

Apache commons net FTP clients hangs unpredictably

We tried all the solutions provided in this post (FTP client hangs) but none of them is working. We are using version 3.6 of commons net. Sometimes it hangs while uploading a file, sometimes will checking existence of a directory. Max. file size is around 400 MB. But sometime it hangs even for a small file size < 1KB. Below is the fragment of code:
public boolean uploadData(String inputFilePath, String destinationFolderName) {
if (StringUtil.isNullOrBlank(inputFilePath) || StringUtil.isNullOrBlank(destinationFolderName)) {
LOGGER.error("Invalid parameters to uploadData. Aborting...");
return false;
}
boolean result = false;
FTPSClient ftpClient = getFTPSClient();
if (ftpClient == null) {
logFTPConnectionError();
return false;
}
try {
loginToFTPServer(ftpClient);
result = uploadFileToFTPServer(ftpClient, inputFilePath, destinationFolderName);
} catch (Exception e) {
logErrorUploadingFile(inputFilePath, e);
return false;
} finally {
try {
logoutFromFTPServer(ftpClient);
} catch (Exception e) {
logErrorUploadingFile(inputFilePath, e);
result = false;
}
}
return result;
}
private FTPSClient getFTPSClient() {
FTPSClient ftpClient = null;
try {
ftpClient = new FTPSClient();
LOGGER.debug("Connecting to FTP server...");
ftpClient.setConnectTimeout(connectTimeOut);
ftpClient.connect(server);
int reply = ftpClient.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
LOGGER.error("Could not connect to FTP server. Aborting.");
return null;
}
} catch (Exception e) {
LOGGER.error("Could not connect to FTP server.", e);
return null;
}
return ftpClient;
}
private void loginToFTPServer(FTPSClient ftpClient) throws Exception {
ftpClient.setDataTimeout(DATA_TIMEOUT);
ftpClient.login(ftpUserName, ftpPassword);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
LOGGER.debug("FTP Client Buffer Size Before:" + ftpClient.getBufferSize());
ftpClient.setBufferSize(BUFFER_SIZE);
LOGGER.debug("FTP Client Buffer Size After:" + ftpClient.getBufferSize());
ftpClient.execPBSZ(0);
ftpClient.execPROT("P");
ftpClient.setControlKeepAliveTimeout(300);
LOGGER.debug("Logged into FTP server.");
}
private void logoutFromFTPServer(FTPSClient ftpClient) throws Exception {
LOGGER.debug("Logging out from FTP server.");
ftpClient.logout();
ftpClient.disconnect();
LOGGER.debug("FTP server connection closed.");
}
private boolean uploadFileToFTPServer(FTPSClient ftpClient, String inputFilePath, String destinationFolderName) {
boolean result = false;
String remoteLocationFile;
File ftpFile = new File(inputFilePath);
try (InputStream inputStream = new FileInputStream(ftpFile)) {
String fileName = ftpFile.getName();
remoteLocationFile = (destinationFolderName == null || destinationFolderName.isEmpty())
? ftpFile.getName()
: destinationFolderName + File.separator + fileName;
LOGGER.info("Storing file " + ftpFile.getName() + " of size "
+ ftpFile.length() + " in folder " + remoteLocationFile);
result = ftpClient.storeFile(remoteLocationFile, inputStream);
if(result) {
LOGGER.info("Successfully stored file " + ftpFile.getName() + " in folder " + remoteLocationFile);
} else {
LOGGER.error("Unable to store file " + ftpFile.getName() + " in folder " + remoteLocationFile);
}
return result;
} catch (Exception e) {
logErrorUploadingFile(inputFilePath, e);
}
return result;
}
The application is hosted in apache tomcat 8. What could be other causes of this issue and how should we fix them? This is crucial functionality of our application and we may even consider to use alternate API if that is stable. Please suggest.
Adding ftpClient.setSoTimeout(20000); has fixed the issue.
Adding a enterLocalPassiveMode right before the retreiveFile should solve this issue.
You also need to add
ftpClient.setControlKeepAliveTimeout(300);
or Check this code which will resolve the hanging issue

On clicking the JTable row, the valueChanged(ListSelectionEvent e) method is calling multiple times

I have the JTable with multiple columns. When I clicked on the table rows, the value changed method call multiple times and at last it throw an error of
java.lang.ArrayIndexOutOfBoundsException: -1
My code is
subjectTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
#Override
public void valueChanged(ListSelectionEvent e) {
System.out.println("Value IS Adjusting --> " + e.getValueIsAdjusting());
try {
if(subjectTable.getSelectedRow() == -1)
return;
if(!e.getValueIsAdjusting()) {
System.out.println("Selected Row --> " + subjectTable.getSelectedRow());
System.out.println("Selected Value of Column 0 --> " + subjectTable.getValueAt(subjectTable.getSelectedRow(), 0).toString());
cmbClass.setSelectedItem(subjectTable.getValueAt(subjectTable.getSelectedRow(), 0).toString());
txtSubjectName.setText(subjectTable.getValueAt(subjectTable.getSelectedRow(), 1).toString());
txtFullMarks.setText(subjectTable.getValueAt(subjectTable.getSelectedRow(), 2).toString());
txtPassMarks.setText(subjectTable.getValueAt(subjectTable.getSelectedRow(), 3).toString());
cmbGrade.setSelectedItem(subjectTable.getValueAt(subjectTable.getSelectedRow(), 4).toString());
}
} catch (IndexOutOfBoundsException ex) {
ex.printStackTrace();
new KILogger("Error in the value changed, Edit Subject table", ex);
}
}
});
I got the error like this:
I didn't know what is this issue. But now it is solved by doing following code:
subjectTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
#Override
public void valueChanged(ListSelectionEvent e) {
try {
if(subjectTable.getSelectedRow() == -1)
return;
if(!e.getValueIsAdjusting()) {
txtSubjectName.setText(subjectTable.getValueAt(subjectTable.getSelectedRow(), 1).toString());
txtFullMarks.setText(subjectTable.getValueAt(subjectTable.getSelectedRow(), 2).toString());
txtPassMarks.setText(subjectTable.getValueAt(subjectTable.getSelectedRow(), 3).toString());
cmbGrade.setSelectedItem(subjectTable.getValueAt(subjectTable.getSelectedRow(), 4).toString());
}
} catch (IndexOutOfBoundsException ex) {
ex.printStackTrace();
new KILogger("Error in the value changed, Edit Subject table", ex);
}
}
}); `

Save and delete image file using parse on heroku and mongoDB

I used heroku with mongoDB for using parse. I deployed parse-server-example and followed all of migration guide.
I want to save PNG file and delete it.
There are some problems T_T
When i save image file and seeing on mongoDB, file name is different from i want to save.
When i delete it using parse code on Android, fs.chunks and fs.files are left.
For 1st problem code is below
Java : Saving image file
Drawable drawable = getResources().getDrawable(R.drawable.ic_loading);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] img_write = stream.toByteArray();
ParseFile parseFile = new ParseFile("test.png", img_write);
testObject = new ParseObject("TestObject");
testObject.put("test", parseFile);
testObject.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.e("Write", "SUCCESS");
} else {
Log.e("Write", e.getMessage());
}
}
});
but when i retrieve image it's value of 'test(key)' is '32de5cf8c1b205a8e26367dae3b07ca3_test.png' though i made ParseFile's name for "test.png" and saved it to 'test(key)'.
For 2nd problem code is below
query = ParseQuery.getQuery("TestObject");
query.whereContains("test", "test.png");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
objectId = objects.get(0).getObjectId();
query.getInBackground(objectId, new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
object.deleteInBackground(new DeleteCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.e("Delete", "SUCCESS");
} else {
Log.e("Delete", e.getMessage());
}
}
});
} else {
Log.e("getInBackground", e.getMessage());
}
}
});
} else {
Log.e("findInBackground", e.getMessage());
}
}
});
I used 'whereContains' because it's name is '32de5cf8c1b205a8e26367dae3b07ca3_test.png'. And when i delete it 'TestObject' be null but 'fs.files' and 'fs.chunks' are left. I know it is kind of grid file. But is it right that when i delete it, grid files are left?
Please help me for my problems...Thank you for reading my questions.

Eclipse Plugin Creating a IJavaLineBreakpoint programmatically does not show method info in Breakpoints view

I'm creating a Eclipse plugin and I'm trying to create JavaLineBreakpoint using JDIDebugModel.
However, when a line breakpoint is created from the Java editor, it displays the Class name, the line number and the method name as the following image:
When the line breakpoint is created in the plugin the method name is replaced by the class name as follows:
The following is the code used to create the breakpoint.
Thank you.
IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints();
if (breakpoints.length == 0) {
return null;
}
IJavaLineBreakpoint oldBreakpoint = null;
for (int i = 0; i < breakpoints.length; i++) {
IBreakpoint breakpoint = breakpoints[i];
if (breakpoint instanceof IJavaLineBreakpoint) {
oldBreakpoint = (IJavaLineBreakpoint)breakpoint;
break;
}
}
if (oldBreakpoint != null) {
Map newAttrMap = null;
IResource resource = null;
try {
IMarker marker = oldBreakpoint.getMarker();
if (marker != null && marker.exists()) {
newAttrMap = marker.getAttributes();
resource = marker.getResource();
}
} catch (CoreException ce) {
Activator.logError("SinfoniaCloudBreakpointItem - Contructor - Marker attributes not found", ce);
}
int lineNumber = -1;
try {
lineNumber = (Integer)newAttrMap.get(IMarker.LINE_NUMBER);
} catch (ClassCastException cce) {
} catch (NullPointerException ne) {
}
try {
JDIDebugModel.createLineBreakpoint(
resource,
oldBreakpoint.getTypeName(),
lineNumber, -1, -1, 0, true, newAttrMap);
oldBreakpoint.delete();
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

wicket download output stream

I want to download csv file , i take the response content and write to it , apprently wicket write after me and the content iam getting is the page html where it should be my csv
I have seen in the example the usage of throw new AbortException();
I am using version 6.7 , do you know if my version wicket has somthing instead of it ?
or rather I am doing somthing wrong ....
can you please help me ...
add(new Link<Void>("export") {
#Override
public void onClick() {
WebResponse response = (WebResponse) getResponse();
response.setAttachmentHeader("export.csv");
response.setContentType("text/csv");
OutputStream out = getResponse().getOutputStream();
try {
c.exportData(dataSource.getListForExport(), columns, out);
} catch (Exception ex) {
System.err.println(ex);
}
}
});
public <T> void exportData(List<T> list, List<IGridColumn<IDataSource<T>, T, String>> columns, OutputStream outputStream)
throws IOException {
long startTime = System.nanoTime();
PrintWriter out = new PrintWriter(new OutputStreamWriter(outputStream, Charset.forName(characterSet)));
try {
if (isExportHeadersEnabled()) {
boolean first = true;
for (IGridColumn<IDataSource<T>, T, String> col : columns) {
if (first) {
first = false;
} else {
out.print(delimiter);
System.out.println(delimiter);
}
if (col.getId().equals("checkBox")) {
continue;
}
out.print(quoteValue(col.getId()));
System.out.println(col.getId());
}
out.print("\r\n");
System.out.println("\r\n");
}
Iterator<? extends T> rowIterator = list.iterator();
while (rowIterator.hasNext()) {
T row = rowIterator.next();
boolean first = true;
for (IGridColumn<IDataSource<T>, T, String> col : columns) {
if (first) {
first = false;
} else {
out.print(delimiter);
System.out.println(delimiter);
}
if (col.getId().equals("checkBox")) {
continue;
}
Object o = (new PropertyModel<>(row, col.getId())).getObject();// ((AbstractColumn<T,
if (o != null) {
Class<?> c = o.getClass();
String s;
IConverter converter = Application.get().getConverterLocator().getConverter(c);
if (converter == null) {
s = o.toString();
} else {
s = converter.convertToString(o, Session.get().getLocale());
}
out.print(quoteValue(s));
System.out.println(quoteValue(s));
}
}
out.print("\r\n");
System.out.println("\r\n");
}
} catch (Exception ex) {
System.out.println(ex);
} finally {
System.out.println(out);
out.close();
// measure
System.out.print(System.nanoTime() - startTime);
}
}
The best way to do this is using dynamic resources. I'll suggest you to read chapter "Resource managment with Wicket" of this magnific free Wicket guide: https://code.google.com/p/wicket-guide/.
Here you have a similar example given in this guide in the section "Custom resources".
public class RSSProducerResource extends AbstractResource {
#Override
protected ResourceResponse newResourceResponse(Attributes attributes) {
ResourceResponse resourceResponse = new ResourceResponse();
resourceResponse.setContentType("text/xml");
resourceResponse.setTextEncoding("utf-8");
resourceResponse.setWriteCallback(new WriteCallback()
{
#Override
public void writeData(Attributes attributes) throws IOException
{
OutputStream outputStream = attributes.getResponse().getOutputStream();
Writer writer = new OutputStreamWriter(outputStream);
SyndFeedOutput output = new SyndFeedOutput();
try {
output.output(getFeed(), writer);
} catch (FeedException e) {
throw new WicketRuntimeException("Problems writing feed to response...");
}
}
});
return resourceResponse;
}
// method getFeed()...
}
And then you need to add the link in the desired page or component:
add(new ResourceLink("rssLink", new RSSProducerResource()));