Aspose barcode null pointer exception in Red Hat OpenShift

Aspose barcode jar is throwing java null pointer exception while trying to generate the barcode image in the code.
facing this issue in Red Hat Open Shift environment, the same code working fine and generating the barcode images in local and PCF(Pivotal Cloud Foundry),initially tried with Aspose bar code jar 16.10 and faced the same issue so tried to migrate to 23.9 and tested in OpenShift environment still facing the same issue.
Java version : openJDK version “1.8.0_382”

@manasag,

Could you please share sample (runnable) Java code/program to reproduce the issue on our end? We will check your issue soon.

try{
currentDirectory = System.getProperty(PrintServerBoImplConstants.USER_DIRECTROY);
if(null != entrySet.getValue() && !PrintServerBoImplConstants.EMPTY.equalsIgnoreCase(entrySet.getValue())){
LOGGER.info(“barcode values {}”, entrySet.getValue());
LOGGER.info(“barcode name {}”,entrySet.getKey());
// builder = new BarCodeBuilder(entrySet.getValue(), Symbology.Code39Extended);
//Cell Image Replace have error Fix
// LOGGER.info(“barcode name {}”, barcodeImageName);
builder = new BarcodeGenerator(EncodeTypes.CODE_39_EXTENDED);
// builder.getParameters().getImageWidth();
builder.getParameters().getBarcode().getCodeTextParameters().setLocation(CodeLocation.NONE);
builder.getParameters().getBarcode().getPadding().getBottom().setPixels(0);
builder.getParameters().getBarcode().getPadding().getLeft().setPixels(0);
builder.getParameters().getBarcode().getPadding().getRight().setPixels(0);
builder.getParameters().getBarcode().getPadding().getTop().setPixels(0);
builder.getParameters().getBarcode().getXDimension().setPixels(1);
// builder.getParameters().setAutoSizeMode(AutoSizeMode.NEAREST);
LOGGER.info(“getvalue” +entrySet.getValue());
builder.setCodeText(entrySet.getValue());
String barcodeImageName = entrySet.getKey()+keyValuePair.get(PrintServerBoImplConstants.LETTER_ID);
bufferedImage = imageResize(builder.generateBarCodeImage(),builder.generateBarCodeImage().getWidth(),PrintServerBoImplConstants.BAR_CODE_IAMGE_HEIGHT);
//Cell Image Replace have error Fix
//bufferedImage = builder.generateBarCodeImage();
//String barcodeImageName = entrySet.getKey()+keyValuePair.get(PrintServerBoImplConstants.LETTER_ID);

						outputfile = new File(currentDirectory+PrintServerBoImplConstants.BACK_SLASH+barcodeImageName+PrintServerBoImplConstants.BARCODE_IMAGE_EXTENSION);
						ImageIO.write(bufferedImage, PrintServerBoImplConstants.BARCODE_IMAGE_FORMAT, outputfile);
						findandInsertHyperlinkImage = new FindandInsertHyperlinkImage(currentDirectory+PrintServerBoImplConstants.BACK_SLASH+barcodeImageName+PrintServerBoImplConstants.BARCODE_IMAGE_EXTENSION);
						FindReplaceOptions options = new FindReplaceOptions();
						options.setReplacingCallback(findandInsertHyperlinkImage);
						document.getRange().replace(Pattern.compile(PrintServerBoImplConstants.STAR_WITH_SINGLE_BACK_SLASH+placeHolderText+PrintServerBoImplConstants.STAR_WITH_SINGLE_BACK_SLASH),"", options);
					}else{
						FindReplaceOptions options = new FindReplaceOptions();
						options.setFindWholeWordsOnly(false);
						options.setMatchCase(false);
						document.getRange().replace(PrintServerBoImplConstants.STAR+placeHolderText+PrintServerBoImplConstants.STAR, entrySet.getValue(),options);
					}
					
				}catch(Exception exception){
					 LOGGER.error("BarCode Conversion have error" +exception);								
					 throw new PrintServerPdfServiceException(PrintServerBoImplConstants.ERROR_IN_BARCODE_REPLACE);
				}

@manasag,

Thanks for the code segment. We will evaluate it and get back to you soon.

@manasag,

We need to investigate your issue in details. We have opened the following new ticket(s) in our internal issue tracking system and will figure it out according to the terms mentioned in Free Support Policies.

Issue ID(s): BARCODEJAVA-1725

Once we have an update on it, we will let you know.

just wanted to check, if there is any update on this issue and here I am attaching the test barcode

public class samplebarcode {

public static void main(String[] args) {
	// TODO Auto-generated method stub

try{
//BarCodeBuilder builder = new BarCodeBuilder(“01”, EncodeTypes.CODE_39_EXTENDED);
BarcodeGenerator builder=new BarcodeGenerator (EncodeTypes.CODE_39_EXTENDED,“01”);
System.out.println(builder);
builder.save(“test.png”);
}catch(Exception e){
e.printStackTrace();
}
}

and this was the error in open shift, while in local it is working fine

Exception in thread “main” java.lang.ExceptionInInitializerError
at com.aspose.barcode.internal.jjt.gg.(Unknown Source)
at com.aspose.barcode.internal.sst.nn.(Unknown Source)
at com.aspose.barcode.internal.vvo.ee.b(Unknown Source)
at com.aspose.barcode.internal.sst.ll.(Unknown Source)
at com.aspose.barcode.internal.sst.ll.(Unknown Source)
at com.aspose.barcode.internal.kke.oo.a(Unknown Source)
at com.aspose.barcode.generation.FontUnit.getFont(Unknown Source)
at com.aspose.barcode.internal.llr.ee.a(Unknown Source)
at com.aspose.barcode.internal.hhr.nn.a(Unknown Source)
at com.aspose.barcode.internal.hhr.nn.a(Unknown Source)
at com.aspose.barcode.internal.hhr.nn.a(Unknown Source)
at com.aspose.barcode.generation.qq.b(Unknown Source)
at com.aspose.barcode.generation.qq.a(Unknown Source)
at com.aspose.barcode.generation.qq.a(Unknown Source)
at com.aspose.barcode.generation.BarcodeGenerator.save(Unknown Source)
at com.aspose.barcode.generation.BarcodeGenerator.save(Unknown Source)
at com.aspose.barcode.generation.BarcodeGenerator.save(Unknown Source)
at com.samplebarcode.main(samplebarcode.java:14)
Caused by: java.lang.NullPointerException
at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219)
at sun.awt.FontConfiguration.init(FontConfiguration.java:107)
at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774)
at sun.font.SunFontManager$2.run(SunFontManager.java:441)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.SunFontManager.(SunFontManager.java:386)
at sun.awt.FcFontManager.(FcFontManager.java:35)
at sun.awt.X11FontManager.(X11FontManager.java:57)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83)
at java.security.AccessController.doPrivileged(Native Method)
at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74)
at sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:190)
at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:224)
at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:97)
at com.aspose.barcode.internal.ppo.ww.(Unknown Source)
… 18 more

@manasag,

Apparently, your issue seems to be related to missing fonts in your Red Hat Open Shift environment. Please add/install the fonts in your environment and then give it a try again.

could you please help us with the steps to install/add the fonts in open shift environment

@manasag,

You may browse internet to find the relevant documents/blogs or threads for your reference.
e.g.,
https://stackoverflow.com/questions/51307075/docker-and-java-fontconfiguration-issue

we are seeing the below error in the open shift for aspose barcode

Caused by: java.lang.ExceptionInInitializerError

361at com.aspose.barcode.internal.ggt.gg.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

362at com.aspose.barcode.internal.ppt.nn.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

363at com.aspose.barcode.internal.nno.ee.b(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

364at com.aspose.barcode.internal.ppt.ll.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

365at com.aspose.barcode.internal.ppt.ll.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

366at com.aspose.barcode.internal.gge.oo.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

367at com.aspose.barcode.generation.FontUnit.getFont(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

368at com.aspose.barcode.internal.jjr.ee.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

369at com.aspose.barcode.internal.ffr.nn.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

370at com.aspose.barcode.internal.ffr.nn.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

371at com.aspose.barcode.internal.ffr.nn.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

372at com.aspose.barcode.generation.qq.b(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

373at com.aspose.barcode.generation.qq.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

374at com.aspose.barcode.generation.BarcodeGenerator.generateBarCodeImage(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

375at com.esrx.services.printserver.pdf.service.utils.PrintServerBoImplUtils.setLogoAndBarcode(PrintServerBoImplUtils.java:2000) ~[app/:?]

376at com.esrx.services.printserver.pdf.service.utils.PrintServerBoImplUtils.getPDFDocument(PrintServerBoImplUtils.java:739) ~[app/:?]

377at com.esrx.services.printserver.pdf.service.utils.PrintServerBoImplUtils.pdfConversion(PrintServerBoImplUtils.java:214) ~[app/:?]

378at com.esrx.services.printserver.pdf.service.component.PrintServerBoImpl.getPdfByLetterId(PrintServerBoImpl.java:150) ~[app/:?]

379at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_392]

380at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_392]

381at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_392]

382at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_392]

383at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

384at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

385at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

386at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

387at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.lambda$doSubmit$3(AsyncExecutionAspectSupport.java:276) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

388at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) ~[?:1.8.0_392]

389at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_392]

390at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_392]

391… 1 more
Caused by: java.lang.NullPointerException

393at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) ~[?:1.8.0_392]

394at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219) ~[?:1.8.0_392]

395at sun.awt.FontConfiguration.init(FontConfiguration.java:107) ~[?:1.8.0_392]

396at sun.awt.X11FontManager.createFontConfiguration(X11FontManager.java:774) ~[?:1.8.0_392]

397at sun.font.SunFontManager$2.run(SunFontManager.java:441) ~[?:1.8.0_392]

398at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_392]

399at sun.font.SunFontManager.(SunFontManager.java:386) ~[?:1.8.0_392]

400at sun.awt.FcFontManager.(FcFontManager.java:35) ~[?:1.8.0_392]

401at sun.awt.X11FontManager.(X11FontManager.java:57) ~[?:1.8.0_392]

402at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_392]

403at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_392]

404at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_392]

405at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_392]

406at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_392]

407at sun.font.FontManagerFactory$1.run(FontManagerFactory.java:83) ~[?:1.8.0_392]

408at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_392]

409at sun.font.FontManagerFactory.getInstance(FontManagerFactory.java:74) ~[?:1.8.0_392]

410at sun.java2d.SunGraphicsEnvironment.getFontManagerForSGE(SunGraphicsEnvironment.java:190) ~[?:1.8.0_392]

411at sun.java2d.SunGraphicsEnvironment.getAvailableFontFamilyNames(SunGraphicsEnvironment.java:224) ~[?:1.8.0_392]

412at sun.java2d.HeadlessGraphicsEnvironment.getAvailableFontFamilyNames(HeadlessGraphicsEnvironment.java:97) ~[?:1.8.0_392]

413at com.aspose.barcode.internal.iio.ww.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

414at com.aspose.barcode.internal.ggt.gg.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

415at com.aspose.barcode.internal.ppt.nn.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

416at com.aspose.barcode.internal.nno.ee.b(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

417at com.aspose.barcode.internal.ppt.ll.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

418at com.aspose.barcode.internal.ppt.ll.(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

419at com.aspose.barcode.internal.gge.oo.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

420at com.aspose.barcode.generation.FontUnit.getFont(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

421at com.aspose.barcode.internal.jjr.ee.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

422at com.aspose.barcode.internal.ffr.nn.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]
at com.aspose.barcode.internal.ffr.nn.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

424at com.aspose.barcode.internal.ffr.nn.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

425at com.aspose.barcode.generation.qq.b(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

426at com.aspose.barcode.generation.qq.a(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

427at com.aspose.barcode.generation.BarcodeGenerator.generateBarCodeImage(Unknown Source) ~[aspose-barcode-23.9.jar:23.9]

428at com.esrx.services.printserver.pdf.service.utils.PrintServerBoImplUtils.setLogoAndBarcode(PrintServerBoImplUtils.java:2000) ~[app/:?]

429at com.esrx.services.printserver.pdf.service.utils.PrintServerBoImplUtils.getPDFDocument(PrintServerBoImplUtils.java:739) ~[app/:?]

430at com.esrx.services.printserver.pdf.service.utils.PrintServerBoImplUtils.pdfConversion(PrintServerBoImplUtils.java:214) ~[app/:?]

431at com.esrx.services.printserver.pdf.service.component.PrintServerBoImpl.getPdfByLetterId(PrintServerBoImpl.java:150) ~[app/:?]

432at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_392]

433at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_392]

434at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_392]

435at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_392]

436at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

437at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

438at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

439at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

440at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.lambda$doSubmit$3(AsyncExecutionAspectSupport.java:276) ~[spring-aop-5.1.5.RELEASE.jar:5.1.5.RELEASE]

441at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) ~[?:1.8.0_392]

442at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[?:1.8.0_392]

443at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_392]

444… 1 more

It seems you still have not installed the fonts properly in your environment. Anyways, since we have already logged your issue (we logged a ticket with an id “BARCODEJAVA-1725” for it) into our database. Currently, you issue is pending for analysis and investigation due to other important tasks (on hand). We will try to evaluate your issue soon.

Once we have an update on it, we will let you know.

we were also using Aspose word and PDF and they were working fine in Open Shift without any additional configuration

could you please let us know what fonts do we need to install in the open shift

@manasag ,

Please check the Github thread/document if it helps a bit.

@manasag
The particular font is not being called from our product code here.
You can try to create a new empty project without any dependencies on the Aspose.Barcode library and run the test below.
This is the point from which the JDK method
sun.awt.FontConfiguration.getVersion():String
is called.
So run the following test:

@Test
    public void test1()
    {
        String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(Locale.ROOT);
        Arrays.stream(availableFonts).forEach(System.out::println);
    }

Our stack:

getVersion:1264, FontConfiguration (sun.awt)
readFontConfigFile:219, FontConfiguration (sun.awt)
init:107, FontConfiguration (sun.awt)
createFontConfiguration:182, Win32FontManager (sun.awt)
run:441, SunFontManager$2 (sun.font)
doPrivileged:-1, AccessController (java.security)
<init>:386, SunFontManager (sun.font)
<init>:89, Win32FontManager (sun.awt)
newInstance0:-1, NativeConstructorAccessorImpl (sun.reflect)
newInstance:62, NativeConstructorAccessorImpl (sun.reflect)
newInstance:45, DelegatingConstructorAccessorImpl (sun.reflect)
newInstance:423, Constructor (java.lang.reflect)
newInstance:442, Class (java.lang)
run:83, FontManagerFactory$1 (sun.font)
doPrivileged:-1, AccessController (java.security)
getInstance:74, FontManagerFactory (sun.font)
getFontManagerForSGE:190, SunGraphicsEnvironment (sun.java2d)
getAvailableFontFamilyNames:224, SunGraphicsEnvironment (sun.java2d)
test1:15, BARCODEJAVA1725 (issues.reproduce)

Line sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
is a point where your example crashes with java.lang.NullPointerException

Please check this test and give feedback.
Do not add any dependencies to Aspose.Barcode product.
If the error is reproduced again then the cause of the error is in the installed JDK.