openIMAJ face detection - uncaught IOException - java

I have this method(simplified) for detecting faces(count) on images(URLs):
private int processImage(String urlString) {
InputStream is = null;
URLConnection resource;
int facesCount = 0;
try {
resource = new URL(urlString).openConnection();
resource.setConnectTimeout(200);
resource.setReadTimeout(1000);
resource.setRequestProperty("User-Agent", "Mozilla/5.0");
String type = resource.getHeaderField("Content-Type");
if (!type.startsWith("image/")) {
throw new IOException("Not an image (Content-Type:" + type + ")");
}
is = resource.getInputStream();
MBFImage mbfimage = ImageUtilities.readMBF(is);
facesCount = faceDetector.detectFaces(Transforms.calculateIntensity(mbfimage)).size();
is.close();
} catch (IOException e) {
System.out.println("oops");
}
return facesCount;
}
It works well, but if the image is somewhat corrupted (for example this test image), i get this error:
Error: Cannot decode the image for the type : Occurs in:
com.sun.media.jai.opimage.CodecRIFUtil java.io.IOException: Source
stream does not support seeking backwards. at
com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76)
at
com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:40)
at
com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:88)
at com.sun.media.jai.opimage.FPXRIF.create(FPXRIF.java:46) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:102) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819) at
javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867) at
javax.media.jai.RenderedOp.getColorModel(RenderedOp.java:2242) at
javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2498)
at
javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:162)
at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:273)
at image.ImageThread.processImage(ImageThread.java:233) at
image.ImageThread.main(ImageThread.java:255) Caused by:
java.lang.IllegalArgumentException: Source stream does not support
seeking backwards. at
com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:200)
at
com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:262)
at
com.sun.media.jai.codecimpl.fpx.StructuredStorage.getFat(StructuredStorage.java:238)
at
com.sun.media.jai.codecimpl.fpx.StructuredStorage.(StructuredStorage.java:131)
at com.sun.media.jai.codecimpl.fpx.FPXImage.(FPXImage.java:110)
at
com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:38)
... 28 more
and the program hangs. I want to catch that exception, log it and go on.
Could you please help me?

Ok, I found the solution. I was using old version of openIMAJ (1.1.3). The latest version is 1.3.1 which works well. I didn't notice, because I overlooked the version numbers.

Related

How to read data from smart card using jmrtd and scuba

I'm trying to read data from ePassporta using jmrtd and scuba.
But it doesn’t work. In Android, almost the same code works.
And when reading from a smart card it doesn’t work.
My method for reading:
public static void reader() throws Exception {
try {
CardTerminal terminal =TerminalFactory.getDefault().terminals().list().get(0);
CardService cs = CardService.getInstance(terminal);
PassportService service = new PassportService(cs);
service.open();
BACKeySpec bacKey = new BACKey("12312312312312", "31121990", "311230");
boolean paceSucceeded = false;
try {
CardAccessFile cardAccessFile = new CardAccessFile(service.getInputStream(PassportService.EF_CARD_ACCESS));
Collection<PACEInfo> paceInfos = cardAccessFile.getPACEInfos();
if (paceInfos != null && paceInfos.size() > 0) {
PACEInfo paceInfo = paceInfos.iterator().next();
service.doPACE(bacKey, paceInfo.getObjectIdentifier(), PACEInfo.toParameterSpec(paceInfo.getParameterId()));
paceSucceeded = true;
} else {
paceSucceeded = true;
}
} catch (Exception e) {
e.printStackTrace();
}
service.sendSelectApplet(paceSucceeded);
if (!paceSucceeded) {
try {
service.getInputStream(PassportService.EF_COM).read();
} catch (Exception e) {
service.doBAC(bacKey);
}
}
LDS lds = new LDS();
CardFileInputStream dg1In = service.getInputStream(PassportService.EF_DG1);
lds.add(PassportService.EF_DG1, dg1In, dg1In.getLength());
DG1File dg1File = lds.getDG1File();
System.out.println(dg1File.getMRZInfo().toString());
} catch (CardServiceException e) {
e.printStackTrace();
}
}
pom.xml
<dependency>
<groupId>org.jmrtd</groupId>
<artifactId>jmrtd</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>net.sf.scuba</groupId>
<artifactId>scuba-sc-j2se</artifactId>
<version>0.0.13</version>
</dependency>
<dependency>
<groupId>net.sf.scuba</groupId>
<artifactId>scuba-smartcards</artifactId>
<version>0.0.13</version>
</dependency>
Stacktrace :
add more text just for stack overflow to accept the question.
added full stacktrace content.
added full stacktrace content.
added full stacktrace content.
added full stacktrace content.
D:\Java\jdk\bin\java -Didea.launcher.port=7539 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0\bin" -Dfile.encoding=UTF-8 -classpath "D:\Java\jdk\jre\lib\charsets.jar;D:\Java\jdk\jre\lib\deploy.jar;D:\Java\jdk\jre\lib\javaws.jar;D:\Java\jdk\jre\lib\jce.jar;D:\Java\jdk\jre\lib\jfr.jar;D:\Java\jdk\jre\lib\jfxswt.jar;D:\Java\jdk\jre\lib\jsse.jar;D:\Java\jdk\jre\lib\management-agent.jar;D:\Java\jdk\jre\lib\plugin.jar;D:\Java\jdk\jre\lib\resources.jar;D:\Java\jdk\jre\lib\rt.jar;D:\Java\jdk\jre\lib\ext\access-bridge-32.jar;D:\Java\jdk\jre\lib\ext\cldrdata.jar;D:\Java\jdk\jre\lib\ext\dnsns.jar;D:\Java\jdk\jre\lib\ext\jaccess.jar;D:\Java\jdk\jre\lib\ext\jfxrt.jar;D:\Java\jdk\jre\lib\ext\localedata.jar;D:\Java\jdk\jre\lib\ext\nashorn.jar;D:\Java\jdk\jre\lib\ext\sunec.jar;D:\Java\jdk\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk\jre\lib\ext\sunmscapi.jar;D:\Java\jdk\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk\jre\lib\ext\zipfs.jar;C:\Users\maksat\IdeaProjects\smart_card\target\classes;C:\Users\maksat\.m2\repository\org\jmrtd\jmrtd\0.5.2\jmrtd-0.5.2.jar;C:\Users\maksat\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.52\bcprov-jdk15on-1.52.jar;C:\Users\maksat\.m2\repository\net\sf\scuba\scuba-sc-j2se\0.0.11\scuba-sc-j2se-0.0.11.jar;C:\Users\maksat\.m2\repository\net\sf\scuba\scuba-smartcards\0.0.9\scuba-smartcards-0.0.9.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain paket.ReadFromSmartCard
net.sf.scuba.smartcards.CardServiceException: File not found, CAPDU = 00A4020C02011C, RAPDU = 6A82 (SW = 0x6A82: FILE NOT FOUND)
at org.jmrtd.PassportApduService.checkStatusWordAfterFileOperation(Unknown Source)
at org.jmrtd.PassportApduService.sendSelectFile(Unknown Source)
at org.jmrtd.PassportService.sendSelectFile(Unknown Source)
at org.jmrtd.MRTDFileSystem.getFileInfo(Unknown Source)
at org.jmrtd.MRTDFileSystem.getSelectedPath(Unknown Source)
at net.sf.scuba.smartcards.CardFileInputStream.<init>(CardFileInputStream.java:56)
at org.jmrtd.PassportService.getInputStream(Unknown Source)
at paket.ReadFromSmartCard.sdvsdv(ReadFromSmartCard.java:121)
at paket.ReadFromSmartCard.readData(ReadFromSmartCard.java:89)
at paket.ReadFromSmartCard.main(ReadFromSmartCard.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
ноя 19, 2019 10:45:51 AM org.jmrtd.PassportService doBAC
WARNING: BAC failed for BAC key "21009199301195, 100993, 120229"
net.sf.scuba.smartcards.CardServiceException: Mutual authentication failed: expected length: 40 + 2, actual length: 2 (SW = 0x6985: CONDITIONS NOT SATISFIED)
at org.jmrtd.PassportApduService.sendMutualAuth(Unknown Source)
at org.jmrtd.PassportService.doBAC(Unknown Source)
at org.jmrtd.PassportService.doBAC(Unknown Source)
at paket.ReadFromSmartCard.sdvsdv(ReadFromSmartCard.java:140)
at paket.ReadFromSmartCard.readData(ReadFromSmartCard.java:89)
at paket.ReadFromSmartCard.main(ReadFromSmartCard.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 0

issue deserializing events in protobuf events in apache flink

I am reading events from kinesis in my flink app. the events are in protobuf format. if i use 'com.google.protobuf:protobuf-java:3.7.1' with in the flink app i've no issues. however if i change that to 'com.google.protobuf:protobuf-java:3.10.0' i get the above exception with stack trace
java.lang.IncompatibleClassChangeError: class com.google.protobuf.Descriptors$OneofDescriptor has interface com.google.protobuf.Descriptors$GenericDescriptor as super class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.privateGetPublicMethods(Class.java:2917)
at java.lang.Class.getMethods(Class.java:1615)
at org.apache.flink.api.java.typeutils.TypeExtractor.isValidPojoField(TypeExtractor.java:1786)
at org.apache.flink.api.java.typeutils.TypeExtractor.analyzePojo(TypeExtractor.java:1856)
at org.apache.flink.api.java.typeutils.TypeExtractor.privateGetForClass(TypeExtractor.java:1746)
at org.apache.flink.api.java.typeutils.TypeExtractor.privateGetForClass(TypeExtractor.java:1643)
at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfoWithTypeHierarchy(TypeExtractor.java:921)
at org.apache.flink.api.java.typeutils.TypeExtractor.privateCreateTypeInfo(TypeExtractor.java:781)
at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfo(TypeExtractor.java:735)
at org.apache.flink.api.java.typeutils.TypeExtractor.createTypeInfo(TypeExtractor.java:731)
at org.apache.flink.api.common.typeinfo.TypeInformation.of(TypeInformation.java:211)
at org.apache.flink.api.java.typeutils.ListTypeInfo.<init>(ListTypeInfo.java:45)
at com.bagi.streaming.serialization.ProtoSchema.getProducedType(ProtoSchema.java:40)
at org.apache.flink.streaming.connectors.kinesis.serialization.KinesisDeserializationSchemaWrapper.getProducedType(KinesisDeserializationSchemaWrapper.java:57)
at org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer.getProducedType(FlinkKinesisConsumer.java:363)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1456)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1414)
at org.apache.flink.streaming.api.environment.StreamExecutionEnvironment.addSource(StreamExecutionEnvironment.java:1396)
at com.bagi.streaming.StreamProcessor.getKinesisTrackingStream(StreamProcessor.java:101)
at com.bagi.streaming.StreamProcessor.getKinesisTrackingStream(StreamProcessor.java:110)
at com.bagi.streaming.StreamProcessor.consumeKinesis(StreamProcessor.java:117)
at com.bagi.streaming.StreamProcessor.main(StreamProcessor.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)
at org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:423)
at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:813)
at org.apache.flink.client.cli.CliFrontend.runProgram(CliFrontend.java:287)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:213)
at org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1050)
at org.apache.flink.client.cli.CliFrontend.lambda$main$11(CliFrontend.java:1126)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1844)
at org.apache.flink.runtime.security.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41)
at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1126)
i am using flink#1.8.0 and 'com.twitter:chill-protobuf:0.9.3'. i am building flink app jar locally on my mac. i've tried using protoc at both 3.10.0 and 3.7.1 for protobuf-java at 3.10.0 in case that matters.
here is my deserializer
public class ProtoSchema implements DeserializationSchema<List<Event>> {
#Override
public List<Event> deserialize(byte[] message) throws IOException {
List<Event> events = new LinkedList<>();
InputStream inputStream = new ByteArrayInputStream(message);
while (true) {
Event event = Event.parseDelimitedFrom(inputStream);
if (event != null) {
events.add(event);
} else {
break;
}
}
return events;
}
#Override
public boolean isEndOfStream(List<Event> nextElement) {
return false;
}
#Override
public TypeInformation<List<Event>> getProducedType() {
return new ListTypeInfo<>(Event.class);
}
}
which i am plugging in by doing
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
Properties consumerConfig = new Properties();
consumerConfig.put(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER, "AUTO");
consumerConfig.put(AWSConfigConstants.AWS_REGION, region);
consumerConfig.put(ConsumerConfigConstants.SHARD_GETRECORDS_INTERVAL_MILLIS, "300");
consumerConfig.put(ConsumerConfigConstants.SHARD_GETRECORDS_RETRIES, "10");
consumerConfig.put(ConsumerConfigConstants.SHARD_GETRECORDS_MAX, "5000");
consumerConfig.put(ConsumerConfigConstants.STREAM_INITIAL_POSITION, "LATEST");
env.addSource(new FlinkKinesisConsumer<>(name, new ProtoSchema(), consumerConfig)).name("KinesisSource");
env.getConfig().registerTypeWithKryoSerializer(Event.class, ProtobufSerializer.class);
Event.class is compiled from protobuf schema using protoc#3.10.0 and protobuf-java#3.10.0
As you said in comment from protobuf-java:3.9.0 there is binary incompatible change to lower versions (3.8-).
to class class Descriptors.OneofDescriptor added super-class Descriptors.GenericDescriptor,
which
A static field from a super-interface of a client class may hide a field (with the same name) inherited from new super-class and cause IncompatibleClassChangeError exception. More
So if you have on your classpath protobuf-java:3.9.0+ and also some lower version (3.8-) call this class you will got this error. (In my case it went from hadoop which has 2.5 protobuf-java version and my fat jar with 3.10)
Solution:
You need to shade one of the incompatible dependencies protobuf-java more how to shade depedency with gradle
Or use version 3.8 and lower as temporary shortsighted solution.

Eclipse Plugin: If Annotation is not present, AbstractAnnotationHover results in a NullPointerException

What i have: I develop an Eclipse editor and override the getTextHover Method in the SourceViewerConfiguration with this method:
public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
return new AbstractAnnotationHover(true) {
public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) {
IAnnotationModel model = ((SourceViewer) textViewer).getAnnotationModel();
#SuppressWarnings("unchecked")
Iterator<Annotation> parent =
((IAnnotationModelExtension2)model).getAnnotationIterator(hoverRegion.getOffset(),
hoverRegion.getLength(), true, true);
Iterator<?> iter = new JavaAnnotationIterator(parent, false);
Annotation annotation = null;
Position position = null;
while (iter.hasNext()) {
Annotation a = (Annotation) iter.next();
Position p = model.getPosition(a);
annotation = a;
position = p;
}
return new AnnotationInfo(annotation, position, textViewer) {
public ICompletionProposal[] getCompletionProposals() {
ICompletionProposal proposal1 = null;
IMarkerResolution [] resolutions = null;
ICompletionProposal [] com = null;
if (annotation instanceof MarkerAnnotation) {
resolutions = new ErrorResolution().getResolutions(((MarkerAnnotation) annotation).getMarker());
if(resolutions.length != 0){
proposal1 = new MarkerResolutionProposal(resolutions[0],
((MarkerAnnotation) annotation).getMarker());
return new ICompletionProposal[] { proposal1 };
}
}
return com ;
}
};
}
};
}
It displays QuickFixes when hovering over an annotated error in the code viewer. But if i hover over an error, which has no quick fix or just a correct line of code, it results in the following error:
org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
at org.eclipse.swt.SWT.error(SWT.java:4491)
at org.eclipse.swt.SWT.error(SWT.java:4406)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:139)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.NullPointerException
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover$AnnotationInformationControl.createAnnotationInformation(AbstractAnnotationHover.java:329)
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover$AnnotationInformationControl.deferredCreateContent(AbstractAnnotationHover.java:282)
at org.eclipse.jdt.internal.ui.text.java.hover.AbstractAnnotationHover$AnnotationInformationControl.setInput(AbstractAnnotationHover.java:186)
at org.eclipse.jface.text.AbstractInformationControlManager.internalShowInformationControl(AbstractInformationControlManager.java:1181)
at org.eclipse.jface.text.AbstractInformationControlManager.presentInformation(AbstractInformationControlManager.java:1150)
at org.eclipse.jface.text.AbstractHoverInformationControlManager.presentInformation(AbstractHoverInformationControlManager.java:902)
at org.eclipse.jface.text.TextViewerHoverManager.doPresentInformation(TextViewerHoverManager.java:243)
at org.eclipse.jface.text.TextViewerHoverManager$5.run(TextViewerHoverManager.java:233)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 24 more
and the message of the annotation is not shown.
What I want: I want, that if i hover iver an error where a quick fix is available, the quick fix is shown and if there is no one, just the annotation message is shown.

Groovy script to run java main class

I have below code of main class that i am trying to run with gradle . i have attached the sample main class of java and gradle script below.
public class Hello {
public static void main(String[] args) throws IOException {
System.out.println("This is file system watch service");
Path dir = Paths.get("c:\\sid\\");
WatchService service = FileSystems.getDefault().newWatchService();
WatchKey key = dir.register(service, ENTRY_CREATE);
System.out.println("Watching directory: "+dir.toString());
//file creation logic
while(true) {
for (WatchEvent<?> event: key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
if (kind == OVERFLOW) {
continue;
}
WatchEvent<Path> ev = (WatchEvent<Path>)event;
Path filename = ev.context();
}
}
}
}
Also my gradle script is as below
apply plugin: 'java'
task hello1 << {
def process = ['java', '-cp', 'sourceSets.main.runtimeClasspath', 'com.test.gradle.Hello'].execute()
process.in.close()
process.out.close()
process.err.close()
}
task hello << {
ant.java(classpath:'sourceSets.main.runtimeClasspath', classname:'com.test.gradle.Hello', fork:'true')
ant.echo('Done')
}
When I call gradle hello1 from command prompt it says build successful however it seems my main program never gets executed. To see the execution of main program I have added sample sysout and file creation logic with PrintWriter.
I have also tried with ant with gradle hello this is also not working.
Now when i use the gradle task as below removed fork true from previous
task hello << {
ant.java(classpath:'sourceSets.main.runtimeClasspath.asPath', classname:'com.test.gradle.Hello.class')
ant.echo('Done')
}
it is generating below exception
[ant:java] Could not find com.test.gradle.Hello.class. Make sure you have it in
your classpath
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:13
8)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at groovy.util.AntBuilder.performTask(AntBuilder.java:319)
at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:264)
at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(Bas
icAntBuilder.java:72)
at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:147)
at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:203)
at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(Ba
sicAntBuilder.java:87)
at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaC
lassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:116)
at build_1dcr9mg141bsc4tjjgplovccq0$_run_closure2.doCall(C:\Users\sumit\
workspace1\gradleTest\build.gradle:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
90)
Try this
javaexec {
main = 'com.pack.YourClass'
classpath(sourceSets.src.output.classesDir, sourceSets.src.compileClasspath)
args(arg1, arg2)
}

Trouble with GData API while using "DocumentListEntry.updateMedia()" method

I'm using the updateMedia(boolean) method of DocumentListEntry from GData API.
Sometimes this command worked, but in the most times an exception is threw.
The code (documentList is an DocumentListEntry object):
public void flush() throws IOException {
try {
if(((ByteArrayOutputStream)os).size()>0){
documentList.setMediaSource(
new MediaByteArraySource(((ByteArrayOutputStream)os).toByteArray(), mimeType));
documentList.updateMedia(true);
((ByteArrayOutputStream)os).reset();
}
} catch (ServiceException ex) {
throw new IOException(ex);
}
}
The command "documentList.updateMedia(true);" throw's this exception:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:216)
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:162)
at com.ralph.agente.Agent.run(Agent.java:191)
at com.ralph.agente.Agent.run(Agent.java:134)
at company.google.conexao.RecebeObjetoThread.geraSinaisVitaisAgent(RecebeObjetoThread.java:61)
at company.google.conexao.RecebeObjetoThread.run(RecebeObjetoThread.java:133)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.IOException: com.google.gdata.util.InvalidEntryException: Unexpected resource version ID
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>invalidResourceVersion</code><internalReason>Unexpected resource version ID</internalReason></error></errors>
at com.company.google.io.GoogleDocsOutputStream.flush(GoogleDocsOutputStream.java:142)
at com.company.google.io.GoogleDocsOutputStream.close(GoogleDocsOutputStream.java:148)
at br.edu.company.google.processo.GeraSinaisVitaisAgent.bodyAgent(GeraSinaisVitaisAgent.java:133)
... 11 more
Caused by: com.google.gdata.util.InvalidEntryException: Unexpected resource version ID
<errors xmlns='http://schemas.google.com/g/2005'><error><domain>GData</domain><code>invalidResourceVersion</code><internalReason>Unexpected resource version ID</internalReason></error></errors>
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:594)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.update(Service.java:1563)
at com.google.gdata.client.Service.update(Service.java:1530)
at com.google.gdata.client.GoogleService.update(GoogleService.java:583)
at com.google.gdata.client.media.MediaService.update(MediaService.java:484)
at com.company.google.io.GoogleDocsOutputStream.flush(GoogleDocsOutputStream.java:137)
Someone can help me?
I've discovered that was missing the command "documentList.setETag(String)". Then I set an '*' character, and it works!
Reference: http://code.google.com/p/gdata-java-client/issues/detail?id=250#c0

Categories

Resources