Why is this an "illegal class name" in Groovy / Java? [duplicate] - java

I'm using the following code in post-build step of my Jenkins job:
evaluate(new File("Set-BuildBadge.groovy"));
So it runs a script successfully if it does not contain functions.
If inside the script I define a function for example:
def addSummaryWithText(Icon, Text) {
manager.createSummary(Icon).appendText(Text, false)
}
...
addSummaryWithText("installer.gif", "Project: " + ProjectName)
then I get the following error:
FATAL: Illegal class name "Set-BuildBadge$addSummaryWithText" in class
file Set-BuildBadge$addSummaryWithText java.lang.ClassFormatError:
Illegal class name "Set-BuildBadge$addSummaryWithText" in class file
Set-BuildBadge$addSummaryWithText at
java.lang.ClassLoader.defineClass1(Native Method) ...
I'm not getting how GroovyShell.evaluate works.
Can anyone help me?

Looks like the JVM doesn't like class names with a hyphen in them.
By calling your script Set-BuildBadge.groovy internally it is compiled into a class that isn't allowed when you add a function to the script.
Changing the name of the script to SetBuildBadge.groovy will fix it :-)

Related

Can we delete records from Meta Dictionary

I am trying to re-compile one of the .Java file in Oracle 11g and I am getting the below error:
$ . /dboracle/orabase/product/11.2.0.BTSP8/bin/loadjava -verbose -resolve -synonym -user nm/nm -grant PUBLIC DeviceAttribParserConstants.java
arguments: '-user' 'nm/***' '-verbose' '-resolve' '-synonym' '-grant' 'PUBLIC' ' DeviceAttribParserConstants.java'
creating : source com/bt/nmsloader/model/DeviceAttribParserConstants
loading : source com/bt/nmsloader/model/DeviceAttribParserConstants
Error while creating source com/bt/nmsloader/model/DeviceAttribParserConstants
ORA-29542: class com/bt/nmsloader/model/DeviceAttribParserConstants already defined by source DeviceAttribParserConstants/java
ORA-06512: at line 1
The following operations failed
source com/bt/nmsloader/model/DeviceAttribParserConstants: creation (createFailed)
exiting : Failures occurred during processing
When I have looked in the ALL_Objects meta-dictionary I did not found JAVA SOURCE but can only see JAVA CLASS for DeviceAttribParserConstants.
Now when I am trying to recompile then I am getting above error and if I am dropping the same JAVA class file then I am getting error as below:
ORA-29537: class or resource cannot be created or dropped directly.
ORA-06512: at line1
* Cause: An attempt was made to create or drop JAVA class or resources that is a known result from compilation of an existing JAVA Source object.
I am stuck. Can someone help me in resolving this error.
Many thanks in advance.
Regards,
Himmy Chauhan
Can we delete records from Meta Dictionary
You shouldn't as it is likely to corrupt your database.
Now when I am trying to recompile then I am getting above error and if I am dropping the same JAVA class file then I am getting error as below:
ORA-29537: class or resource cannot be created or dropped directly.
ORA-06512: at line1
* Cause: An attempt was made to create or drop JAVA class or resources that is a known result from compilation of an existing JAVA Source object.
The loadjava utility has a force option:
-force Forces files to be loaded, even if they match digest table entries.
So you can try:
loadjava -verbose -force -resolve -synonym -user nm/nm -grant PUBLIC DeviceAttribParserConstants.java
You can also try to drop the existing java object:
SELECT OWNER, OBJECT_NAME
FROM ALL_OBJECTS
WHERE OWNER = 'NM'
AND OBJECT_NAME LIKE '%DeviceAttribParserConstants';
DROP JAVA CLASS NM.<insert_object_name>
and then try using loadjava without the force option.
(You may want to try backing up the existing class file before you drop/overwrite it just in case you need to revert to the prior version.)

How to resolve exception attempting to load java class in DB2 Java Stored procedure?

I have created Java.sqlj program and done with creating packages and jar, when attempting to call the procedure, facing the error like
ATTEMPTING‬‎ ‪TO‬‎ ‪LOAD‬‎ ‪JAVA‬‎ ‪CLASS‬‎ ‪s1‬‎.‪S1Sal‬‎ ‪FROM‬‎ ‪JAR‬‎ ‪COEDB‬‎.‪S1SAL‬‎
Here s1‬‎.‪S1Sal - Where s1 is the package name and S1Sal is class name and it's defined in the java program.
Error
‪
Run‬‎:‪‬‎ ‪SYSPROC‬‎.‪S1NUM‬‎(‪DECIMAL‬‎(‪4‬‎,‪‬‎ ‪0‬‎)‪‬‎)‪
‬‪‬‎{‪call‬‎ ‪SYSPROC‬‎.‪S1NUM‬‎(‪‬‎?‪‬‎)‪‬‎}‪
‬‪USER‬‎-‪DEFINED‬‎ ‪ROUTINE‬‎ ‪SYSPROC‬‎.‪S1NUM‬‎ ‪ENCOUNTERED‬‎ ‪AN‬‎ ‪ EXCEPTION‬‎ ‪ATTEMPTING‬‎ ‪TO‬‎ ‪LOAD‬‎ ‪JAVA‬‎ ‪CLASS‬‎ ‪s1‬‎.‪S1Sal‬‎ ‪FROM‬‎ ‪JAR‬‎ ‪COEDB‬‎.‪S1SAL‬‎.‪‬‎ ‪ ORIGINAL‬‎ ‪EXCEPTION‬‎:‪‬‎ ‪‬‎(‪none‬‎)‪‬‎.‪‬‎ ‪SQLCODE‬‎=‪‬‎-‪20212‬‎,‪‬‎ ‪SQLSTATE‬‎=‪46103‬‎,‪‬‎ ‪DRIVER‬‎=‪4‬‎.‪22‬‎.‪29
‬‪Run‬‎ ‪of‬‎ ‪routine‬‎ ‪failed‬‎.‪
‬‪‬‎ ‪‬‎-‪‬‎ ‪Roll‬‎ ‪back‬‎ ‪completed‬‎ ‪successfully‬‎.‪

Cannot find symbol '/' in class name

When I compile my java class. There are some errors of cannot find symble '/' in class name. Below is a sample code from my class:
public TransactionSearchResponse submit(TxnSearchRequest req)
{
url = (new StringBuilder(String.valueOf(req.getBaseUrl()))).append("/txns/search").toString();
method = "POST";
return (TransactionSearchResponse)sendRequest(req, com/COMPPONENT/api/TransactionSearchResponse);
}
Be cause of copyright from author of this code block. sendRequest Method is deleted.
Netbeans cannot recognize the dash '/' in the class name "com/COMPPONENT/api/TxnResp". And the class name contains some parts:
Package name: com.COMPONENT.api
Class name: TxnResp
Java file name: TxnResp.java
The dash '/' show in red color as Netbeans mask it an error line. The only hint I got from Netbeans are "Add import for com.COMPONENT.api.TxnResp" or "Flip Operands of '/' (may alter semantics), and I did that but got no luck. And when I try to run the code, it generate an error of "Cannot find symbol". Can you help me to solve this issue?
Regards,
Dung Tri
If a method sendRequest is declared like
Object sendRequest( Request x, Class<?> y )
you'll have to call it with an instance of a java.lang.Class object:
... = sendRequest( request, com.COMPPONENT.api.TxnResp.class );
Appending .class is the way of obtaining an instance of a certain Class object (not to be confused with an instance of TxnResp which is created using new TxnResp).
Also, given
com.COMPPONENT.api.TxnResp txnResp = new com.COMPPONENT.api.TxnResp();
the expression
txnResp.getClass()
results in an instance of the Class<com.COMPPONENT.api.TxnResp> but of course the .class notation is more convenient for your purpose.

BeanShell command line interpreter features

I'm trying to test BeanShell's command line interpreter in how it processes basic Java commands and syntax on my machine, and see if I can customise its behavior in any way. I've installed version 2.0b4 on my machine running OS X 10.10.1 (the JAR file is in /Library/Java/Extensions as per the instructions).
It's the closest thing to what I've been looking for, an interactive Java interpreter, but it doesn't have some standard features which a good interpreter should have.
I'd like to be able to use the Up arrow key to reuse a previous command, but at the moment it doesn't recognise it, it just shows a control sequence. Is there a way to customise this for BeanShell?
Is there a way to get BeanShell to print out the value of a variable if I've created it beforehand, just by naming it, like
String s = new String( "Hello World!" );
s;
Hello World!.
This is possible in Python for example.
According to the documentation on importing Java classes which(<java class>); should return the classpath location of the specified Java class. But which( java.lang.String ); does not work for me, I get a NullPointerException:
bsh % which(java.lang.String);
Start ClassPath Mapping
Mapping: Directory /Users/srm
// Error: // Uncaught Exception: Method Invocation cp.getClassSource : at Line: 42 : in file: /bsh/commands/which.bsh : cp .getClassSource ( className )
Called from method: which : at Line: 8 : in file: : which ( java .lang .String )
Target exception: java.lang.NullPointerException
java.lang.NullPointerException
Any pointers or help would be appreciated.
Run beanshell with jline.
Download jline jar from http://jline.sourceforge.net/index.html and then you can do:
java -cp jline-1.0.jar:bsh-2.0b4.jar jline.ConsoleRunner bsh.Interpreter
Line editing capability will be provided by jline. I found this hint here.
There are issues running with jline2. First, you'll get:
$ java -cp jline-2.12.jar:bsh-2.0b4.jar jline.ConsoleRunner bsh.Interpreter
Exception in thread "main" java.lang.NoClassDefFoundError: jline/ConsoleRunner
Due to this issue which is fixed. But then, use the new class and you still get:
$ java -cp jline-2.12.jar:bsh-2.0b4.jar jline.console.internal.ConsoleRunner bsh.Interpreter
Exception in thread "main" java.lang.IllegalArgumentException: wrong number of arguments
due to this issue which is not fixed yet.
Use show() command which will trigger showing of value.
bsh % show();
bsh % String s = new String("Hello World");
bsh % s;
<Hello World>
bsh %
It is mentioned in the Useful BeanShell Commands section of the documentation.
Doesn't work for me either
It doesn't fail in my case, but it didn't find it either.
bsh % which(java.lang.String);
Start ClassPath Mapping
Mapping: Archive: file:/Users/me/beanshell/jline-1.0.jar
Mapping: Archive: file:/Users/me/beanshell/bsh-2.0b4.jar
Mapping: Archive: file:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar
End ClassPath Mapping
null
bsh %

NoClassDefFound error using Jode obfuscator

I'm using jode's obfuscator in an attempt to obfuscate all of the class files in my jar. I've packaged all the class files in the jar, so that I can use the config to specify what I need loading, and what I need preserving.
Here is my package hierarchy:
src
src.loading
src.loading.org
src.loading.sign
Here's what I've specified as my wildcards:
load = new WildCard { value = "src.*" }
preserve = new WildCard { value = "src.loading.org.*" }
And this is the error I get (Decompiling too. It's the only class.)
C:\Users\Kieran\Desktop\jode>java jode.obfuscator.Main project.jos
Jode (c) 1998-2001 Jochen Hoenicke <jochen#gnu.org>
used before: 479080
Loading and preserving classes
Exception in thread "main" java.lang.NoClassDefFoundError: src.loading.Class48
at jode.bytecode.ClassInfo.loadInfo(ClassInfo.java:631)
at jode.obfuscator.ClassIdentifier.initClass(ClassIdentifier.java:371)
Exception while decompiling:java.lang.NoClassDefFoundError: src.loading.Class48
at jode.bytecode.ClassInfo.loadInfo(ClassInfo.java:631)
at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:86)
at jode.decompiler.ClassAnalyzer.<init>(ClassAnalyzer.java:123)
at jode.decompiler.Decompiler.decompile(Decompiler.java:191)
at jode.swingui.Main.run(Main.java:204)
at java.lang.Thread.run(Unknown Source)
The class does exist, and I the jar file is fully functional. Why am I getting this error?
This specific class is using reflection, to access java.lang.Runtime, could this be the issue...?

Categories

Resources