Class not found error for com.sun.tool.javac in OSGI - dynamic

I am porting an old Java code base to OSGI. In the old code base there is dynamic code generation used. Example a string is compiled to generate Java classes using
com.sun.tools.javac.Main.compile.
I was reusing the same code and added com.sun.tools.javac in etc/custom.properties -> org.osgi.framework.system.packages.extra:= com.sun.tools.javac.Main of Karaf.
During runtime I get the exception java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
Could anyone please help me out with some suggestions to overcome the problem.

I don't know Karaf but why do you use := instead of just = in the property setting? Also, the property value is a list of package names, not type names. So the interesting package is "com.sun.tools.javac".

Related

Razor view errors while Migrating from core 2.2 to 3.1

After doing the general upgrade steps for the migration. My razor had 100's of errors suddenly after removing Microsoft.AspNetCore.All. These error were not consistent, these were general compiler errors.
Some combination of
IDE1007 C# The name does not exist in the current context.
CS0111 C# Type already defines a member called with the same parameter types
CS0538 C# in explicit interface declaration is not an interface
CS0116 C# A namespace cannot directly contain members such as fields
or methods
CS8107 C# Feature is not available in C# 7.0. Please use
language version 9.0 or greater.
Just all over the place stuff, and this was all working perfectly in 2.2
I was able to fix this. What I found was that we had few places in the code where we were using # inside a razor block, this used to work fine but breaks in core 3.1. I am assuming that the process of generating the classes by Razor SDK was failing because I was also getting errors in index.g.cshtml.cs.
We probably had this issue in 5 files at most but we were getting 500+ build errors. Very frustrating, so adding this answer because I was not able to find any similar answer anywhere.
Example of bad code, notice the extra # inside {}.
#{ var replacements = new string[] { #Model.TotalItemsInCart.ToString() };}

Is there a way to find where the internal classes are moved

We are migrating our application from Eclipse Indigo to Photon and I need help find a solution or alternate for a particular class which is present in Indigo but not in Photon.
The class we are trying to figure out is org.eclipse.ui.internal.navigator.AdaptabilityUtility.
Since it is an Internal class it is not available. But we had no luck finding an alternate.
Only one function of the class is used :
IAdaptable openable = (IAdaptable) AdaptabilityUtility.getAdapter(
selection.getFirstElement(), IResource.class);
If someone knows an alternative method which can be used here, it will be a great help.
Eclipse internals were completely rewritten for Eclipse 4 so in general there may not be exact alternatives for internal classes which were never part of the official API.
However for AdaptabilityUtility it looks like the current org.eclipse.core.runtime.Adapters class should work:
IResource resource = Adapters.adapt(selection.getFirstElement(), IResource.class);
Adapters.adapt uses generics so casts are not needed. Adapters is not internal so it is an official API.

fhir java proto not compiling / missing symbols

I tried downloading the google-fhir repo and running generate-proto.sh, which generated a bunch of java files in ~/fhir-master/proto/stu3/target/com/google/fhir/stu3/proto which won't compile. Many objects cannot be resolved: com.google.fhir.stu3.proto.ReferenceOrBuilder getCoverageOrBuilder();, com.google.fhir.stu3.proto.PositiveInt getPriority();, etc.
At some point, I also generated a bunch of classes (not sure how now, but I think it was with hazel. if you know, please tell me) in com/google/fhir/stu3/proto. However when I try to use these classes to extract the schema, none of the symbols can be found: java.lang.NoClassDefFoundError: com/google/fhir/stu3/proto/IdOrBuilder and error: cannot find symbol, etc.
How do I get all the dependencies to work? How could this possible work out of the box?
Your question is kind of confusing based on the code and explanation but I will answer your question. If you are compiling your avro schema to java class you should be able to get the schema like this
Account.$SCHEMA
Now if you are asking how can create and schema from a POJO in java, you can do it like this
Schema schema = ReflectData.get().getSchema(YourClass.class);
About the exception that you are getting, is hard to help you without context or more code to understand what you are trying to do and how.

Warn-as-error for MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved

After I have fixed this warning, how can I make it an error, so it doesn't slip in again?
msbuild /p:TreatWarningsAsErrors doesn't work
No happy answer to give you here. The TreatWarningsAsErrors property only affects the C# and VB.NET compiler (not C++), it determines the value of their /warnaserror command line option.
But MSB3277 is generated by an MSBuild task, ResolveAssemblyReference, its internal LogResult() method generates the diagnostic. The only property the class has that helps treat warnings as errors conditionally is WarnOrErrorOnTargetArchitectureMismatch, not what you are trying to achieve. You can have a look-see for yourself with a decompiler, look at C:\Program Files (x86)\MSBuild\12.0\Bin\Microsoft.Build.Tasks.v12.0.dll. The resource name for the localized MSB3277 message is "ResolveAssemblyReference.FoundConflicts".
So only way to get ahead here is to write a little utility that parses the log file and looks for the warning.
You can use the generic mechanism MSBuildTreatWarningsAsErrors or <MSBuildWarningsAsErrors>MSB3277</MSBuildWarningsAsErrors> (introduced in #1928) to accomplish this.
credit: rainersigwald
Run Update-Package via Package Manager Console, this will fix MSB3277, what it does it reinstall all the packages and all related assemblies they come with to the highest version possible.
More info on official docs https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages
It looks like the /warnaserror will promote all msbuild warnings to errors:
TreatWarningsAsErrors vs /warnaserror

'Requested bean is currently in creation' on a domain object

I'm trying to migrate from grails 1.2.2 to 1.3.6 and got the following error when trying to access a page :
Error creating bean with name 'com.example.domain.UserAccount': Requested bean is currently in creation: Is there an unresolvable circular reference?
It seems that grails tryed to instanciate UserAccount as a spring bean (probably to be able to inject some dependencies).
Is there some constraints that appears on grails 1.3.x that were not relevant on 1.2.x ?
Thanks & Regard,
David.
The problem was coming from a property in the UserAccount class :
Program program = new Program(user:this)
The this reference was escaping from the object construction before the end of the construction.
Your best bet would be to read through the release notes for the versions between your old and new version used. If that does not shed any light, you might also consider doing incremental upgrades, one version at a time... that would be a big pain, but might be the more revealing way to upgrade.
Good luck.