setBorder() function throwing NullPointerExcepiton

Hi Team,

I am facing some weired issue while I am setting border of particular range.

I have below method which setBorder :

public static void setBorders(Range compRange) throws ServiceException {
try {
if (compRange != null) {
Style style = compRange.getWorksheet().getWorkbook().createStyle();
style.getFont().setName(“Arial”);
style.getFont().setSize(10);
style.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
style.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
style.setBorder(BorderType.HORIZONTAL, CellBorderType.NONE, Color.getEmpty());
style.setBorder(BorderType.VERTICAL, CellBorderType.NONE, Color.getEmpty());

			StyleFlag sf = new StyleFlag();
			sf.setFontName(true);
			sf.setFontSize(true);
			sf.setBorders(true);
			compRange.applyStyle(style, sf);
		}
	} catch (Exception ex) {
		LOG.error("Error in AsposeUtil.setBorders() ", ex);
		throw new ServiceException("Error in AsposeUtil.setBorders() ", ex);
	}
}

But I am getting below exception :
[2014-11-03 09:11:52,046] ERROR AsposeUtil(setBorders:1060): Error in AsposeUtil.setBorders()
java.lang.NullPointerException
at com.aspose.cells.Style.setBorder(Unknown Source)
at com.rsi.report.util.AsposeUtil.setBorders(AsposeUtil.java:1050)
at com.rsi.reportserver.aspose.renderer.AsposeCommonReportServerRenderer.appyFormatingAfterSubTotal(AsposeCommonReportServerRenderer.java:3520)
at com.rsi.reportserver.aspose.renderer.AsposeRollingPeriodReportServerRenderer.processContents(AsposeRollingPeriodReportServerRenderer.java:170)
at com.rsi.reportserver.aspose.renderer.AsposeRollingPeriodReportServerRenderer.run(AsposeRollingPeriodReportServerRenderer.java:238)
at com.rsi.reportserver.processor.RollingPeriodReportRenderer.renderReport(RollingPeriodReportRenderer.java:32)
at com.rsi.reportserver.processor.ReportRenderer.processReport(ReportRenderer.java:73)
at com.rsi.reportserver.service.ReportServerHelper.processReport(ReportServerHelper.java:476)
at com.rsi.reportserver.service.ReportServerHelper.processReport(ReportServerHelper.java:443)
at com.rsi.reportserver.service.ReportServerServiceImpl.processReport(ReportServerServiceImpl.java:105)
at com.rsi.report.service.ReportGenerationJob.execute(ReportGenerationJob.java:297)
at com.rsi.core.job.service.jobengine.JobRunShell$2.process(JobRunShell.java:117)
at com.rsi.core.job.service.jobengine.TransactionTask.call(TransactionTask.java:29)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

This error get generated very less time, not every call will generate this exception.

If possible, could you please help me to check which code will throw this exception.

Thanks,
Gauri

Hi,


Well, to evaluate your issue properly, we need to simulate the issue on our end. Please create a sample console demo JAVA program (runnable) to replicate your issue on our end (you may also attach the template file if any), so we could look into it and log a ticket for the issue (if found) into our database to figure it out soon.

Thank you.

Hi Amjad,

Actually we are facing this nullpointer exception issue on production environment. If I use same input on my local environment and run the code, not getting this exception.

I am also unable to replicate that issue locally.

As per stack trace its throwing exception in setBorder() method. This method using all ASPOSE standard API.

Do you have any guess, from where we can get this null pointer exception.

Please once again have look on setBorder() method which I provided earlier.

Your help is really appreciable.

Thanks,
Gauri

Hi,


We have evaluated your issue a bit, I am afraid, we could not find the possible cause(s) for such kind of the issue you mentioned. We will do more investigation later on though. We may give you further reply as soon as we find some clue for your issue. We may also need more things and other details from your side as well.

We will get back to you soon.

Thank you.

Hi,

Which version of Aspose.Cells are you using? If possible please test it with the latest versions of Aspose.Cells for JAVA to check whether this issue has been fixed. For some older versions’, setting border for BorderType.HORIZONTAL and BorderType.VERTICAL may cause such kind of exception, but it should not occur with recent versions. Also you can just remove the lines of code:
e.g
Sample code:

.........

style.setBorder(BorderType.HORIZONTAL, CellBorderType.NONE, Color.getEmpty());

style.setBorder(BorderType.VERTICAL, CellBorderType.NONE, Color.getEmpty());

and test it again with the Aspose.Cells version that you are using now, maybe your issue can be solved too.

Thank you

Hi Amjad,

Thanks for your reply.

We are using aspose-cells-8.0.1.jar file on production environment.

Does this jar file have issue for BorderType.HORIZONTAL and BorderType.VERTICAL ??

Thanks,
Gauri

Hi Amjad,

I am using java with aspose-cells-8.0.1.jar. I tried below code :

Workbook workbook = new Workbook();

	//Accessing the added worksheet in the Excel file
	int sheetIndex = workbook.getWorksheets().add();
	Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
	Cells cells = worksheet.getCells();

	//Accessing the "A1" cell from the worksheet      
	Cell cell = cells.get("C10");

	//Adding some value to the "A1" cell
	cell.setValue("Visit Aspose!");
	Style style = cell.getStyle();

	style.getFont().setName("Arial");
	style.getFont().setSize(10);
	style.setBorder(BorderType.TOP_BORDER, CellBorderType.THIN, Color.getBlack());
	style.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.THIN, Color.getBlack());
	style.setBorder(BorderType.LEFT_BORDER, CellBorderType.THIN, Color.getBlack());
	style.setBorder(BorderType.RIGHT_BORDER, CellBorderType.THIN, Color.getBlack());
	style.setBorder(BorderType.HORIZONTAL, CellBorderType.NONE, Color.getEmpty());
	style.setBorder(BorderType.VERTICAL, CellBorderType.NONE, Color.getEmpty());
	
	StyleFlag sf = new StyleFlag();
	sf.setFontName(true);
	sf.setFontSize(true);
	sf.setBorders(true);
	
	
	//Saving the modified style to the "A1" cell.
	cell.setStyle(style);

	//Saving the Excel file
	workbook.save("D:\\ASPOSE\\setBorder.xlsx");

Its running properly.

Thanks,
Gauri

Hi,


Thanks for your feedback.

Good to know that it is working fine with v8.0.1 as well. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.


Thank you.

Hi Amjad,

On production env I am using ASPOSE v8…0.1 jar file and getting that exception. But same jar I used locally, then running smoothly.

Could you please specify which version have this Nullpointer issue??

Thanks,
Gauri

Hi,


We recommend and request you to test your issue with the latest versions of Aspose.Cells for JAVA (v8.2.1) to check whether it is fixed in it or got the same issue on your production server.

Thank you.

Hi,

It seems the version you are using should not give such exception for setting border for BorderType.HORIZONTAL and BorderType.VERTICAL. Unfortunately, we cannot find the possible cause of such an exception in Style.setBorder() by analyzing the Style.setBorder() method only. Was the workbook(compRange.getWorksheet().getWorkbook()) created from one template file? If so, please send us the template file too, maybe the issue is related with some special template file. Furthermore, if you have other operations on the workbook/style before setting the borders, please simulate those operations as much as possible in your test case, that may also help us to reproduce the issue or analyze the possible cause of it. And you can also try our proposal of removing the code of setting border for BorderType.HORIZONTAL and BorderType.VERTICAL. And you can try our latest version too to see whether the issue has been solved by the new version or not.

Thank you

Hi Amjad,

Could you please update us, in which jar you fixed the issue related to BorderType horizontal and vertical?

We are facing issue after using ASPOSE latest 8.2.0.4.jar as well.

Still I am unable to reproduce issue locally.

Yes we are using the template file to create workbook.
I tried on my local environment by using QA env template as well, but unable to reproduce it.
Don’t think so its template related issue.

Please update us : in which version fixed setborder related issue?

Thanks,
Gauri

Could you please update us.

Hi,


Well, for the issue of setting horizontal/vertical
border, it should have been fixed from v7.1.0 and later versions.

Would you please confirm that v8.2.0.4 gives this exception but v8.2.0.3 or v8.2.0.0 can work fine for your application? It may help us to figure the issue out if we could know from which version the behavior changes.

Also please confirm that the issue randomly occurs for different template files. We doubt it is a template related issue because of one possibility: if borders of workbook’s default style are not instantiated completely when reading template file, NPE (NullPointerException) may be thrown for your code. If it is not related to special template file, please check whether it is only related to one special file format(such as XLS, XLSX, XLSX... etc.). The more details we can get about the issue, it will be easier for us to figure the issue out.

By the way, did you test the case with removing the code for setting horizontal/vertical borders? if not kindly do it and let us know the results as well.


Thank you