I'm trying to capture values in my test
...
final Capture<MyDTO> myDTOCaptured = new Capture<MyDTO>();
EasyMock.expect(this.serviceMock.execute(capture(myDTOCaptured)).andReturn(someResult);
...
The Documentation says:
Deprecated API
org.easymock.EasyMock.capture(Capture)
Because of harder erasure enforcement, doesn't compile in Java 7
http://easymock.sourceforge.net/api/easymock/3.1/deprecated-list.html
Version 3.1 is the version we are using.
Is there any alternative for capture in Java 8+? I guess the alternative is upgrading the version.
Upgrade to latest EasyMock (4.2) and use generic method capture(Capture<T> captured) as a replacement
Expect any object but captures it for later use
Example:
final Capture<TwoWayChannelMessage> initiateCapture = new Capture<>();
connection.sendToClient(capture(initiateCapture));
This website is obsolete. The real up-to-date EasyMock website is http://easymock.org/. EasyMock moved out of SourceForge a long time ago.
Latest EasyMock would be
Capture<TwoWayChannelMessage> initiateCapture = EasyMock.newCapture();
connection.sendToClient(capture(initiateCapture));
Related
I am upgrading a legacy application from Java 8 to Java 11 (Oracle Version) and having issue while getting the corbaloc reference.
I have read below
articles here and here that specifies that CORBA support is removed form JAVA 11 and with the help of Glassfish Corba I can use the packages again.
The issue I am facing is with below function call
((com.sun.corba.se.spi.orb.ORB) orb.orb()).register_initial_reference(idStr, ref);
In Eclipse the Error is ORB cannot be resolved to a type.
As I know we should not use any package related to sun but this is old code and not sure about the replacement.
I have changed the package from com.sun.corba.se.spi.orb.ORB to org.omg.CORBA.ORB but the method register_initial_reference(idStr, ref) is not found.
I am not sure what needs to be changed or any example that will help to get the possible alternate change. Any guide or help is highly appreciated. Even I have almost NO idea about CORBA and very less examples are available.
Below is the function that starts the service
final byte[] id = "\u00ffPNS_Service\u0000PNS_Study".getBytes();
final String idStr = new String(id);
final Policy[] policies = new Policy[] {
root.create_lifespan_policy(LifespanPolicyValue.PERSISTENT) };
final POA poa = root.create_POA("PNS_Service",root.the_POAManager(),policies);
poa.the_POAManager().activate();
poa.activate_object(studyService);
final org.omg.CORBA.Object ref = poa.servant_to_reference(studyService);
((com.sun.corba.se.spi.orb.ORB) orb.orb()).register_initial_reference(idStr , ref);```
I am trying to build a deep learning model with transformer model architecture. In that case when I am trying to cleaning the dataset following error occurred.
I am using Pytorch and google colab for that case & trying to clean Java methods and comment dataset.
Tested Code
import re
from fast_trees.core import FastParser
parser = FastParser('java')
def get_cmt_params(cmt: str) -> List[str]:
'''
Grabs the parameter identifier names from a JavaDoc comment
:param cmt: the comment to extract the parameter identifier names from
:returns: an array of the parameter identifier names found in the given comment
'''
params = re.findall('#param+\s+\w+', cmt)
param_names = []
for param in params:
param_names.append(param.split()[1])
return param_name
Occured Error
Downloading repo https://github.com/tree-sitter/tree-sitter-java to /usr/local/lib/python3.7/dist-packages/fast_trees/tree-sitter-java.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-31-64f6fa6ed39b> in <module>()
3 from fast_trees.core import FastParser
4
----> 5 parser.set_language = FastParser('java')
6
7 def get_cmt_params(cmt: str) -> List[str]:
3 frames
/usr/local/lib/python3.7/dist-packages/fast_trees/core.py in FastParser(lang)
96 }
97
---> 98 return PARSERS[lang]()
/usr/local/lib/python3.7/dist-packages/fast_trees/core.py in __init__(self)
46
47 def __init__(self):
---> 48 super().__init__()
49
50 def get_method_parameters(self, mthd: str) -> List[str]:
/usr/local/lib/python3.7/dist-packages/fast_trees/core.py in __init__(self)
15 class BaseParser:
16 def __init__(self):
---> 17 self.build_parser()
18
19 def build_parser(self):
/usr/local/lib/python3.7/dist-packages/fast_trees/core.py in build_parser(self)
35 self.language = Language(build_dir, self.LANG)
36 self.parser = Parser()
---> 37 self.parser.set_language(self.language)
38
39 # Cell
ValueError: Incompatible Language version 13. Must not be between 9 and 12
an anybody help me to solve this issue?
fast_trees uses tree_sitter and according to tree_sitter repo it is an incomatibility issue. If you know the owner of fast_trees ask them to upgrade their tree_sitter version.
Or you can fork it and upgrade it yourself, but keep in mind it may not be backwards compatible if you take it upon yourself and it may not be just a simple new version install.
The fast-trees library uses the tree-sitter library and since they recommended using the 0.2.0 version of tree-sitter in order to use fast-trees. Although downgrade the tree-sitter to the 0.2.0 version will not be resolved your problem. I also tried out it by downgrading it.
So, without investing time to figure out the bug in tree-sitter it is better to move to another stable library that satisfies your requirements. So, as your requirement, you need to extract features from a given java code. So, you can use javalang library to extract features from a given java code.
javalang is a pure Python library for working with Java source code.
javalang provides a lexer and parser targeting Java 8. The
implementation is based on the Java language spec available at
http://docs.oracle.com/javase/specs/jls/se8/html/.
you can refer it from - https://pypi.org/project/javalang/0.13.0/
Since javalang is a pure library it will help go forward on your research without any bugs
I was using org.refcode.refcodes-console version 1.1.9. When upgrading to 2.0.4, it seems various methods no longer exist.
My scala code:
val theHelp = helpSwitch("Shows this help")
I get this error when compiling: not found: value helpSwitch
Same error when using switsh and StringOptionImpl.
How should I replace them when migrating from 1.x to 2.x for this maven artifact?
All 'switch' (aka switsh) methods in ConsoleSugar have been renamed to 'flag' in major version 2. So 'switsh' has been renamed to 'flag' and 'helpSwitch' has been renamed to 'helpFlag'.
For StringOptionImpl, use 'SpringOption' instead.
So in the example provided, it should now be:
val theHelp = helpFlag("Shows this help")
Also, for the switsh method you would need to add a 'aAlias' parameter as the third parameter. For example:
val block = switsh("-w", "--wait", "Wait at the end of the Program")
would need to be something like become
val block = flag("-w", "--wait", "wait", "Wait at the end of the Program")
I am moving my code from JDK 8 to Open JDK 12. While doing so, I am facing following issue :
java.lang.NoSuchFieldException: scl
while trying to call ClassLoader.class.getDeclaredField("scl"). This was working fine in Java 8 but no longer works in newer Java versions.
I did some findings and believe it has got to do with the way working of reflection and use of internal Java packages have changed since Java 8.
Set<URL> classLoaderUrls = computeClassLoaderUrls();
ClassLoader bootstrapClassLoader = ClassLoader.getSystemClassLoader().getParent();
this.classLoader = new URLClassLoader(classLoaderUrls.toArray(new URL[classLoaderUrls.size()]), bootstrapClassLoader);
Field systemClassLoaderField = ClassLoader.class.getDeclaredField("scl");
systemClassLoaderField.setAccessible(true);
this.initialSystemClassLoader = (ClassLoader) systemClassLoaderField.get(null);
systemClassLoaderField.set(null, this.classLoader);
I want to know , if the way to access these classloader and its fields has changed or should I use some other field instead of scl. Thanks
I'm using lambdaj 2.4 with dependencies. My code (very simple):
List<Person> persons = Arrays.asList(
new Person(13,"Steve",22,"London, UK"),
new Person(25,"Greg",28,"New York, USA"),
new Person(5,"Emily",22,"Bali, Indonesia"),
new Person(9,"Malih",14,"Jakarta, Indonesia"));
List<String> personNames = extract(persons, on(Person.class).getName());
System.out.println("personNames: "+personNames);
But it does not work, exception is:
java.lang.ExceptionInInitializerError
at ch.lambdaj.proxy.ProxyUtil.createEnhancer(ProxyUtil.java:89)
at ch.lambdaj.proxy.ProxyUtil.createProxy(ProxyUtil.java:49)
at ch.lambdaj.function.argument.ArgumentsFactory.createPlaceholder(ArgumentsFactory.java:68)
Any ideas how to make it working on Android?
If you have the choice, you should consider using Retro Lambda. It's a backport of the full Java 8 Lambda Expression syntax for JDK 6 & 7 - and offers full, real closures (LambdaJ was pretty good alternative in the absence of language level support).
Retro Lambda
Retro Lambda Gradle Plugin
Stream Support - backport of Streams
Blog post on setting up RetroLambda for Android Studio