Junit is not working in Maven Project - java

I wrote the following code to read the contents of the arxml file.
#Test
public void second() throws IOException {
private XMLResource resource;
String file = "E:\\Input\\ArText_0001.arxml";
AutosarResourceSetImpl resourceSet = new AutosarResourceSetImpl();
Autosar40ResourceFactoryImpl resourceFactory = new Autosar40ResourceFactoryImpl();
URI uri = URI.createFileURI(file );
Map<?, ?> options = null;
resource = (XMLResource) resourceFactory.createResource(uri);
resource.load(options);
resourceSet.getResources().add(resource);
}
I run the project using clean verify goal , In eclipse its working fine but using maven from command line I am getting the following exception.
java.lang.StackOverflowError: null
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
Finally i got know I am facing the problem in resource.load(option).Instead of option = null I tried the following way also
option.put(Resource.Factory.Registry.DEFAULT_EXTENSION,new Autosar40ResourceFactoryImpl())
But now also i am getting same exception.Please help me to solve this one?
Exception:
Time elapsed: 12.846 sec <<< ERROR!
java.lang.StackOverflowError: null
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.EnvironmentalconditionFactory.<clinit>(EnvironmentalconditionFactory.java:41)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.impl.EnvironmentalconditionPackageImpl.<init>(EnvironmentalconditionPackageImpl.java:1152)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.impl.EnvironmentalconditionPackageImpl.init(EnvironmentalconditionPackageImpl.java:1206)
at autosar40.diagnosticextract.dcm.diagnosticservice.environmentalcondition.EnvironmentalconditionPackage.<clinit>(EnvironmentalconditionPackage.java:84)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
at java.lang.reflect.Field.get(Field.java:393)
at org.eclipse.emf.ecore.plugin.RegistryReader$EPackageDescriptor.getEPackage(RegistryReader.java:275)
at org.eclipse.emf.ecore.impl.EPackageRegistryImpl.getEPackage(EPackageRegistryImpl.java:127)
at autosar40.diagnosticextract.dcm.obdservice.mode_0x0a_requestemissionrelateddtcpermanentstatus.impl.Mode_0x0a_requestemissionrelateddtcpermanentstatusPackageImpl.init(Mode_0x0a_requestemissionrelateddtcpermanentstatusPackageImpl.java:1400)
at autosar40.diagnosticextract.dcm.obdservice.mode_0x0a_requestemissionrelateddtcpermanentstatus.Mode_0x0a_requestemissionrelateddtcpermanentstatusPackage.<clinit>(Mode_0x0a_requestemissionrelateddtcpermanentstatusPackage.java:78)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1088)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1069)
at java.lang.reflect.Field.get(Field.java:393)
at org.eclipse.emf.ecore.plugin.RegistryReader$EPackageDescriptor.getEPackage(RegistryReader.java:275)
at org.eclipse.emf.ecore.impl.EPackageRegistryImpl.getEPackage(EPackageRegistryImpl.java:127)
at autosar40.diagnosticextract.dcm.obdservice.mode_0x09_requestvehicleinformation.impl.Mode_0x09_requestvehicleinformationPackageImpl.init(Mode_0x09_requestvehicleinformationPackageImpl.java:1399)

Related

java.lang.NullPointerException at org.eclipse.jface.resource.JFaceResources.getResources

I am going to implement wizard with SWT / jface. When I run my program, I have the below error:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.jface.resource.JFaceResources.getResources(JFaceResources.java:209)
at org.eclipse.jface.resource.JFaceResources.getImageRegistry(JFaceResources.java:402)
at org.eclipse.jface.wizard.Wizard.<init>(Wizard.java:105)
at mypackage.ReservationWizard.<init>(ReservationWizard.java:21)
at mypackage.ReservationWizard.main(ReservationWizard.java:69)
The part of my code:
public class ReservationWizard extends Wizard {
**public ReservationWizard() {**
// setWindowTitle("Hotel room reservation wizard");
// setNeedsProgressMonitor(true);
// setDefaultPageImageDescriptor(ImageDescriptor.createFromFile(null, "Unknown.jpg"));
}
...
public static void main(String[] args) {
**ReservationWizard wizard = new ReservationWizard();**
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(), wizard);
dialog.setBlockOnOpen(true);
dialog.open();
}
}
As seen in the code it has an error, even when the ReservationWizard() is empty. What should I do?
It has an error on the specified lines.
edit:
When I created a display, I have the below error:
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
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:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jface.resource.JFaceResources.getFontRegistry(JFaceResources.java:340)
at org.eclipse.jface.window.Window.createShell(Window.java:508)
at org.eclipse.jface.window.Window.create(Window.java:429)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1096)
at org.eclipse.jface.window.Window.open(Window.java:792)
at mypackage.ReservationWizard.main(ReservationWizard.java:76)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.commands.common.EventManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 more
You have not created a Display before calling your wizard. The first thing an SWT / JFace application has to do is create the display.
So you need:
public static void main(final String [] args)
{
// Create the display
Display display = new Display();
ReservationWizard wizard = new ReservationWizard();
WizardDialog dialog = new WizardDialog(display.getActiveShell(), wizard);
dialog.setBlockOnOpen(true);
dialog.open();
}

Newly created JUNIT class not found exception (Class not found com.pearson.aimswebplus.controller.TestNavAssignmentListControllerTest)

I created a java file TestNavAssignmentListControllerTest. codes as follows
public class TestNavAssignmentListControllerTest extends
AimswebplusRosterAssesssQueringserverApplicationTests {
#Autowired
private TestnavAssignmentListController testnavAssignmentListController;
#Test
public void searchOk(){
String params = "aimswebId=1168&roster=RCM3MA==&minGrade=0&maxGrade=7&measureCode=&type=&schoolYearVal=2015&benchmarkPeriodId=2&studentsWithNewStatus=0&page=0&size=0&sort=studentName&order=asc&username=manager&assignmentIds=1602,1723,1829,2437";
TestnavAssignmentListDto listDto = (TestnavAssignmentListDto) when().get(BASE_URL + "/query/testnavAssignments?" + params) .as(TestnavAssignmentListDto.class);
assertNotNull(listDto);
}
when I try to run as Junit Test it throws
Class not found com.pearson.aimswebplus.controller.TestNavAssignmentListControllerTest
java.lang.ClassNotFoundException: com.pearson.aimswebplus.controller.TestNavAssignmentListControllerTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:685)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:444)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
exception.
I worked out with : building the project and compiling the project (using maven)
any one have idea about this please let me know.

Java Reflections 'NoClassDef' error

I'm trying to browse all classes that have implemented an interface using the custom libary Reflections. Here is my source :
public static List<IModdable> getAllModClasses() {
Reflections reflections = new Reflections("mod.api.core"); //getting error here
Set<Class<? extends IModdable>> classes = reflections.getSubTypesOf(IModdable.class);
List<IModdable> modList = new ArrayList<IModdable>();
for (Class<? extends IModdable> c : classes)
try {
modList.add((IModdable) c.newInstance());
} catch (Exception ex) {
err(String.format("Could not load mod %s !", c.getName()));
}
return modList;
}
error:
Exception in thread "Client thread" java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:100)
at org.reflections.adapters.JavassistAdapter.getOfCreateClassObject(JavassistAdapter.java:24)
at org.reflections.scanners.AbstractScanner.scan(AbstractScanner.java:30)
at org.reflections.Reflections.scan(Reflections.java:238)
at org.reflections.Reflections.scan(Reflections.java:204)
at org.reflections.Reflections.<init>(Reflections.java:129)
at org.reflections.Reflections.<init>(Reflections.java:170)
at org.reflections.Reflections.<init>(Reflections.java:143)
at mod.api.core.CoreProvider.getAllModClasses(CoreProvider.java:17)
at mod.api.core.ModCore.onLoad(ModCore.java:13)
at net.minecraft.client.Minecraft.run(Minecraft.java:405)
at net.minecraft.client.main.Main.main(Main.java:114)
at Start.main(Start.java:11)
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
The mod.api.core package exits. So that shouldn't be the error.
java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
You can fix the issue by adding javassist-3.12.1.GA.jar to your classpath

Hive StorageHandler throws exception "Configuration and input path are inconsistent"

I have a HiveStorageHandler if I do select * from myTable it returns all the rows in the underlying storage.
When I do something like select col1 from myTable the underlying mapreduce job throws an exception:
java.lang.RuntimeException: Error in configuring object
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:109)
at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:75)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:133)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:413)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:332)
at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1438)
at org.apache.hadoop.mapred.Child.main(Child.java:262)
Caused by: java.lang.reflect.InvocationTargetException
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 org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:106)
... 9 more
Caused by: java.lang.RuntimeException: Error in configuring object
at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:109)
at org.apache.hadoop.util.ReflectionUtils.setConf(ReflectionUtils.java:75)
at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:133)
at org.apache.hadoop.mapred.MapRunner.configure(MapRunner.java:34)
... 14 more
Caused by: java.lang.reflect.InvocationTargetException
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 org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:106)
... 17 more
Caused by: java.lang.RuntimeException: Map operator initialization failed
at org.apache.hadoop.hive.ql.exec.ExecMapper.configure(ExecMapper.java:119)
... 22 more
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: org.apache.hadoop.hive.ql.metadata.HiveException: Configuration and input path are inconsistent
at org.apache.hadoop.hive.ql.exec.MapOperator.setChildren(MapOperator.java:526)
at org.apache.hadoop.hive.ql.exec.ExecMapper.configure(ExecMapper.java:90)
... 22 more
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Configuration and input path are inconsistent
at org.apache.hadoop.hive.ql.exec.MapOperator.setChildren(MapOperator.java:520)
... 23 more
2015-02-12 15:45:51,881 INFO org.apache.hadoop.mapred.Task: Runnning cleanup for the task
If I introduce a HiveMetaHook.preCreateTable and set the location to what my input-path on hdfs is then it works. But my path changes dynamically, and I can't constantly update this property:
#Override
public void preCreateTable(Table tbl) throws MetaException {
if (tbl.getSd().getLocation() != null) {
throw new MetaException("LOCATION should be null.");
}
tbl.getSd().setLocation(*hard-coded-input-path*);
}
I did this based on the following posting.
This was happening because I was changing the the mapred.input.dir on the fly to point to a particular file on hdfs. Now, once i'm finished with own calculations, I set the mapred.input.dir back to what hive had set it to.
I have my own Split for this InputFormat. So every-time FileSplit.getPath() is invoked I return what hive expects which is the original mapred.input.dir and now everything works.
class MySplit extends org.apache.hadoop.mapred.FileSplit {
public MySplit(InputSplit actualSplit, String hiveInputPath) {
super (new Path(hiveInputPath), 0,0, (String[]) null);
this.actualSplit = actualSplit;
}
//do not override getPath that way hiveInputPath is returned
InputSplit getActualSplit() {
return actualSplit;
}
....
}

Class Not Found Exception When Creating New Instance Of Class Inside of Jar - Java

I am trying to create a new instance of a class to invoke a method in Java. But because the class is inside a jar (Which loads just fine), The class cannot. This causes a ClassNotFoundException to be thrown. Could someone please tell me how to fix this?
Code:
private static void loadClassFromJar(String PluginJar) throws MalformedURLException, ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
File PluginFile = new File("./debug/plugins/DiamondCorePlugin.jar");
URL[] PluginURLs = { PluginFile.getAbsoluteFile().toURI().toURL() };
URLClassLoader ClassLoader = URLClassLoader.newInstance(PluginURLs);
Class<?> PluginClass = ClassLoader.loadClass("net.trenterprises.diamondcore.plugin.Main");
Method EventMethod = PluginClass.getMethod("onEnable");
EventMethod.invoke(PluginClass.newInstance());
}
Stack trace:
java.lang.ClassNotFoundException: net.trenterprises.diamondcore.plugin.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at net.trenterprises.diamondcore.cross.api.javaplugin.sub.Server.getClassCaller(Server.java:23)
at net.trenterprises.diamondcore.cross.api.javaplugin.sub.Server.getLogger(Server.java:15)
at net.trenterprises.diamondcore.plugin.Main.onEnable(Main.java:11)
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:483)
at net.trenterprises.diamondcore.cross.api.PluginLoader.loadClassFromJar(PluginLoader.java:55)
at net.trenterprises.diamondcore.cross.api.PluginLoader.loadAllPlugins(PluginLoader.java:25)
at net.trenterprises.diamondcore.DiamondCoreServer.<init>(DiamondCoreServer.java:47)
at net.trenterprises.diamondcore.run.main(run.java:15)
Found the problem! It turned out that the class was loading just fine, but in another class that tried to get the classes name, becuase the class was in a JAR file. It could not load! Thank you for all of the help immibiz and vanza!

Categories

Resources