I have to get the return types or the parent class of method invocations to distinguish between overloaded methods within a workspace. I am currently using javaparser to do the same, however I encountered unresolved symbol exceptions with certain method calls that I observed to be defined within the same class that they were being used in (with exception of a few). The directory given to the JavaParserTypeSolver is the src directory of the project containing the class. A snippet for the part is as follows -
for(ICompilationUnit unit : units) {
File file = new File(workspacePath+pack.getPath()+"\\" + unit.getElementName());
CombinedTypeSolver solver = new CombinedTypeSolver();
solver.add(new ReflectionTypeSolver());
solver.add(new JavaParserTypeSolver(projectPath + "/src"));
TypeSolver typeSolver = solver;
JavaSymbolSolver symbolSolver = new JavaSymbolSolver(typeSolver);
StaticJavaParser.getConfiguration().setSymbolResolver(symbolSolver);
CompilationUnit cu = StaticJavaParser.parse(file);
}
The output showing the methods that it is encountering exceptions with -
secondlevel setEditor
PrintStream println
secondlevel setEditor
PrintStream println
Exception in : getActiveWorkbenchWindow
Exception in : getWorkbench
Exception in : getWorkspace
Exception in : getRoot
Exception in : println
Exception in : getProjects
PrintStream println
Exception in : toString
Exception in : getPackageFragments
Exception in : contains
Exception in : getCompilationUnits
Exception in : println
Exception in : start
Exception in : stop
Exception in : getActiveWorkbenchWindowChecked
Exception in : getActiveEditor
Exception in : getEditorInput
Exception in : getAdapter
Exception in : getWorkspace
Exception in : getRoot
Exception in : getProjects
Exception in : toString
String replaceAll
String replaceAll
Exception in : getProject
Exception in : create
Exception in : createFieldNameAndTypeMap
Exception in : getText
String split
String contains
String contains
String contains
String indexOf
Character isAlphabetic
String substring
String replace
Set add
RefrencesHandler setServiceMethodName
PrintStream println
Exception in : isOpen
Exception in : create
Exception in : isOpen
String split
Map get
String split
String contains
Character isUpperCase
Exception in : searchMethodByString
Exception in : searchMethod
Exception in : searchMethod
String indexOf
Character isAlphabetic
Character isAlphabetic
String substring
String substring
Set add
String replace
String contains
RefrencesHandler setServiceMethodName
Exception in : printStackTrace
Exception in : findType
Exception in : getSignatureSimpleName
Exception in : getFullFileName
Exception in : put
Exception in : getFields
Exception in : resolveType
String length
Exception in : getActiveEditor
Exception in : getDocumentProvider
Exception in : getDocument
Exception in : getSelection
Throwable printStackTrace
Exception in : findType
Exception in : equalsIgnoreCase
Exception in : createWorkspaceScope
Exception in : getMethod
Exception in : createPattern
Exception in : callSearchEngine
Exception in : getMethods
Throwable printStackTrace
Exception in : createPattern
Exception in : createJavaSearchScope
Exception in : println
Exception in : callSearchEngine
Exception in : println
Exception in : getDefaultSearchParticipant
Exception in : search
Exception in : getActiveWorkbenchWindowChecked
Exception in : openInformation
Throwable printStackTrace
PrintStream println
Exception in : listFiles
Exception in : parse
Exception in : getElementsByTag
Exception in : equals
List add
As I mentioned earlier, most of these methods are particularly the ones that are defined within the class itself.
I want to know if I am missing something or doing it wrong. Any alternatives to achieve the same would also be appreciated.
Related
For some reason, I get exception during instantiation of the home controller. I am very puzzled by it. I am thinking that may be it is caused by the different life time scope of the different dependencies - InstancePerDependency and SingleInstance.
using: Autofac.4.0.0
In my Register(). I have:
builder.Register(x => new DepositEligibilityService()).As<IDepositEligibilityService>().InstancePerDependency();
builder.Register(x => new SemanticExceptionManager()).As<IExceptionManager>().SingleInstance();
builder.Register(x => new SemanticLoggingManager()).As<ILoggingManager>().SingleInstance();
and
public class HomeController : BaseController
{
private readonly IAuthenticationManager _authenticationManager;
LoginInfo _loginInfo;
public HomeController(IDepositEligibilityService depositEligibilityService, IExceptionManager exceptionManager, ILoggingManager loggingManager):base(depositEligibilityService, exceptionManager, loggingManager)
{
// ...
}
}
I sometimes get an exception like the following:
Exception information:
Exception type: DependencyResolutionException
Exception message: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = HomeController (ReflectionActivator), Services = [DepositEligibility.Web.Controllers.HomeController], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope ---> An exception was thrown while invoking the constructor 'Void .ctor(DepositEligibility.Web.Services.IDepositEligibilityService, Gdot.Services.SemanticLogging.Interfaces.IExceptionManager, Gdot.Services.SemanticLogging.Interfaces.ILoggingManager)' on type 'HomeController'. ---> Object reference not set to an instance of an object. (See inner exception for details.) (See inner exception for details.)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters)
at System.Web.Mvc.DefaultControllerFactory.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType)
An exception was thrown while invoking the constructor 'Void .ctor(DepositEligibility.Web.Services.IDepositEligibilityService, Gdot.Services.SemanticLogging.Interfaces.IExceptionManager, Gdot.Services.SemanticLogging.Interfaces.ILoggingManager)' on type 'HomeController'. ---> Object reference not set to an instance of an object. (See inner exception for details.)
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
Object reference not set to an instance of an object.
at DepositEligibility.Web.Controllers.BaseController..ctor(IDepositEligibilityService depositEligibilityService, IExceptionManager exceptionManager, ILoggingManager loggingManage)
at DepositEligibility.Web.Controllers.HomeController..ctor(IDepositEligibilityService depositEligibilityService, IExceptionManager exceptionManager, ILoggingManager loggingManager)
at lambda_method(Closure , Object[] )
at Autofac.Core.Activators.Reflection.ConstructorParameterBinding.Instantiate()
How can I use Junit4 to test the thrown exception while using the exception mapper ?
To test a thrown exception, expected from the execution. Please use :
#Test(expected=<ExpectedException>.class)
public void testThrownException() {
// Your test code that throws the expected exception
}
The test would pass if your code throws the expected exception and fail for assertion failures and any other exception thrown by the code.
I'm trying to use Spring-Data-Couchbase.
I want to get List from findAll(Iterable) method.
I set view 'all' to my Production View.
But, I meet the exception.
How Can I use findAll(Iterable) method?
Below is a Sample Code and exception.
Document Class:
#Document
public class User {
#Id
private String id;
private String userSeq;
}
Repository Class :
public interface UserRepository extends CouchbaseRepository<User, String> {
}
Service Class:
//List<String> get the Same result & exception.
Set<String> friendSet = new HashSet<String>();
friendSet.add("User8");
friendSet.add("User6");
userRepository.findAll(friendSet)
Exception:
Caused by: java.util.concurrent.ExecutionException: OperationException: SERVER: bad_request Reason: invalid UTF-8 JSON: {{error,{2,"lexical error: invalid char in json text.\n"}},
"[User8, User6]"}
at com.couchbase.client.internal.HttpFuture.waitForAndCheckOperation(HttpFuture.java:98)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:82)
at com.couchbase.client.internal.HttpFuture.get(HttpFuture.java:72)
at com.couchbase.client.CouchbaseClient.query(CouchbaseClient.java:778)
... 66 more
Caused by: OperationException: SERVER: bad_request Reason: invalid UTF-8 JSON: {{error,{2,"lexical error: invalid char in json text.\n"}},
"[User8, User6]"}
at com.couchbase.client.protocol.views.NoDocsOperationImpl.parseError(NoDocsOperationImpl.java:110)
at com.couchbase.client.protocol.views.ViewOperationImpl.handleResponse(ViewOperationImpl.java:68)
at com.couchbase.client.http.HttpResponseCallback.completed(HttpResponseCallback.java:103)
at com.couchbase.client.http.HttpResponseCallback.completed(HttpResponseCallback.java:51)
at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:115)
at org.apache.http.nio.protocol.HttpAsyncRequester$RequestExecutionCallback.completed(HttpAsyncRequester.java:376)
at org.apache.http.concurrent.BasicFuture.completed(BasicFuture.java:115)
at org.apache.http.nio.protocol.BasicAsyncClientExchangeHandler.responseCompleted(BasicAsyncClientExchangeHandler.java:179)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.processResponse(HttpAsyncRequestExecutor.java:349)
at org.apache.http.nio.protocol.HttpAsyncRequestExecutor.inputReady(HttpAsyncRequestExecutor.java:236)
at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:267)
at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady(DefaultHttpClientIODispatch.java:165)
at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady(DefaultHttpClientIODispatch.java:51)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:113)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:159)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:338)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:316)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:277)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:584)
... 1 more
You have to quote the id:s before you call findAll(...).
Set<String> friendSet = new HashSet<String>();
friendSet.add("\"User8\"");
friendSet.add("\"User6\"");
If the id:s aren't quoted the keys parameter sent to the Couchbase server will look something like [User8, User6] which isn't valid JSON, hence the exception. Pretty surprising behaviour...
What should happen when the value of a property is set to undefined in a json string.
i.e:
{"Name":undefined}
The following example is using the json.net library. An exception is thrown when de-serializing the object.
JsonConvert.DeserializeObject<SimpleObject>("{\"Name\":undefined}");
public class SimpleObject
{
public string Name { get; set; }
}
Newtonsoft.Json.JsonReaderException was unhandled
Message=Error reading string. Unexpected token: Undefined. Path 'Value', line 1, position 18.
Source=Newtonsoft.Json
LineNumber=1
LinePosition=18
Path=Value
I think the error is fine.
Jsonlint.org throws an error too.
And reading the documentation on json.org the "value" element may have the following variants:
string
number
object
array
true
false
null
As you can see, undefined is NOT listed. Object does also not count as undefined.
I am just playing with MessageFormat but when I try to pass a String to MessageFormat format method it compiles fine but then I get a runtime classcast exception. Here is the code.
MessageFormat format = new MessageFormat("");
Object obj = Integer.toHexString(10);
format.format(obj);
Now the runtime exception I get is as follows.
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
at java.text.MessageFormat.format(Unknown Source)
at java.text.Format.format(Unknown Source)
at JavaCore2.Codepoint.main(Codepoint.java:21)
MessageFormat.format() takes an argument of type Object[] (an Object array), whereas you are passing in a single Object.
You will have to create an array out of your Integer:
MessageFormat format = new MessageFormat("{0}");
Object[] args = { Integer.toHexString(10) };
String result = format.format(args);